poj2528(离散化线段树区间更新)
来源:互联网 发布:时时彩模拟软件 编辑:程序博客网 时间:2024/05/26 07:29
这题的离散化有点不一样。要在第一次离散化之后把每个数字之间差不为一的地方在随便填进去一个数。然后就是线段树的区间更新加查询
#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int maxn = 10005;int n,num;int li[maxn];int ri[maxn];int ne[maxn<<3];int clo[maxn<<4];bool hashs[maxn];int ans = 0;void PushDown(int root){ clo[root<<1] = clo[root<<1|1] = clo[root]; clo[root] = -1;}void Update(int L,int R,int c,int l,int r,int root){ if(l>=L&&r<=R) { clo[root] = c; return ; } if(clo[root]!=-1) PushDown(root); int m = (l+r)>>1; if(m>=L) Update(L,R,c,l,m,root<<1); if(m<R) Update(L,R,c,m+1,r,root<<1|1);}void query(int l,int r,int root){ if(l==r){ if(!hashs[clo[root]]){ ans++; hashs[clo[root]] = true; } return ; } if(clo[root]!=-1) PushDown(root); int m = (l+r)>>1; query(l,m,root<<1); query(m+1,r,root<<1|1);}inline int find(int a){ return upper_bound(ne+1,ne+1+num,a)-ne-1;}int main(){ int cases; int tot; scanf("%d",&cases); while(cases--) { scanf("%d",&n); tot = 0; memset(hashs,false,sizeof(hashs)); memset(clo,-1,sizeof(clo)); for(int i=1;i<=n;i++) { scanf("%d%d",&li[i],&ri[i]); ne[++tot] = li[i]; ne[++tot] = ri[i]; } sort(ne+1,ne+tot+1); num = 1; for(int i=2;i<=tot;i++) { if(ne[i]!=ne[i-1]) ne[++num] = ne[i]; } for(int i=num;i>1;i--) if(ne[i]-ne[i-1]>1) ne[++num] = ne[i]-1; sort(ne+1,ne+num+1); for(int i=1;i<=n;i++) { int ll = find(li[i]); int rr = find(ri[i]); Update(ll,rr,i,1,num,1); } ans = 0; query(1,num,1); printf("%d\n",ans); } return 0;}/*1031 101 46 10*/
阅读全文
0 0
- poj2528 离散化+线段树区间更新
- POJ2528 线段树 区间更新 离散化
- poj2528(离散化线段树区间更新)
- poj2528 线段树 区间更新+染色+离散化
- POJ2528:Mayor's posters(线段树区间更新+离散化)
- POJ2528 Mayor's posters 线段树区间更新+离散化
- POJ2528 Mayor's posters(线段树区间更新,离散化)
- poj2528(线段树区间染色+离散化)
- poj2528-Mayor's posters(线段树,区间,离散化)
- poj2528(线段树区间更新)
- 线段树区间更新+poj2528
- POJ2528解题报告,区间离散化,线段树
- poj2528 线段树 区间合并 特殊离散化
- poj2528 (线段树+离散化)
- poj2528(线段树+离散化)
- poj2528(离散化+线段树)
- poj2528(线段树+离散化)
- poj2528 线段树+离散化
- springMVC 整合shiro
- zoj3435 莫比乌斯反演
- 14.说说ATL常用包装类的用法和坑
- Unity3D之设计模式MVC
- 阿里云CentOS Yum 出现Cannot retrieve repository metadata (repomd.xml) for repository: rpmforge
- poj2528(离散化线段树区间更新)
- ReactNative 退出到后台一定时间之后,跳转到登录界面
- Linux team 及网桥
- 士兵杀敌(三) 【nyoj-119】【线段树】
- 南理 奇偶数分离
- 问题 B: 黑色星期五
- Drying
- 《剑指offer》牛客网java题解
- PHP对程序员的要求更高