POJ-2528-Mayor's posters
来源:互联网 发布:六壬排盘软件安卓 编辑:程序博客网 时间:2024/05/19 14:19
线段树+离散化
数组开大些
#include<stdio.h>#include<algorithm>#include<iostream>#include<string.h>#include<stdlib.h>#include<queue>#include<vector>#include<math.h>#include<stack>#include<map>using namespace std;const int MAX = 11111;int col[MAX*20], m[MAX*12], vis[MAX*12];int n, t, cnt, ans;struct node{ int l, r;} lxt[MAX*2];void update(int l, int r, int c, int L, int R, int rt){ if(l<=L&&R<=r) { col[rt] = c; return; } if(col[rt]!=-1) { col[rt<<1] = col[rt<<1|1] = col[rt]; col[rt] = -1; } int mid = (L+R)>>1; if(l<=mid)update(l, r, c, L, mid, rt<<1); if(r>mid)update(l, r, c, mid+1, R, rt<<1|1);}void query(int l,int r, int rt){ if(col[rt]!=-1) { if(!vis[col[rt]]) ans++; vis[col[rt]] = 1; return; } if(l==r)return; int mid = (l+r)>>1; query(l, mid, rt<<1); query(mid+1, r, rt<<1|1);}int main(){ cin>>t; while(t--) { cin>>n; cnt = 0; for(int i = 0; i<n; ++i) { scanf("%d%d", &lxt[i].l, &lxt[i].r); m[cnt++] = lxt[i].l; m[cnt++] = lxt[i].r; } sort(m, m+cnt); int k = 1; for(int i = 1; i<cnt; ++i) if(m[i]!=m[i-1])m[k++] = m[i]; for(int i = k-1; i>=1; --i) if(m[i]-m[i-1]>1)m[k++] = m[i-1]+1; sort(m, m+k); memset(col, -1, sizeof(col)); for(int i = 0; i<n; ++i) { int l = lower_bound(m, m+k, lxt[i].l)-m; int r = lower_bound(m, m+k, lxt[i].r)-m; update(l, r, i+1, 0, k-1, 1); } ans = 0; memset(vis, 0, sizeof(vis)); query(0, k-1, 1); cout<<ans<<endl; } return 0;}
0 0
- POJ 2528 Mayor's posters
- poj 2528 Mayor's posters
- POJ 2528 Mayor's Posters
- Mayor's posters poj 2528
- poj 2528 Mayor's posters
- Poj 2528 Mayor's posters
- poj 2528 Mayor's posters
- POJ 2528 Mayor's posters
- POJ 2528 Mayor's posters
- POJ 2528 - Mayor's posters
- POJ-2528-Mayor's posters
- poj 2528 Mayor's posters
- poj 2528 Mayor's posters
- poj 2528 Mayor's posters
- POJ 2528 Mayor's posters
- POJ 2528 Mayor's posters
- Poj 2528 Mayor's posters
- Poj 2528 Mayor's posters
- There was an error connecting to the Apple ID server 解决方法
- awk的使用实例
- JS和Jquery获取选中select值和文本
- java 煤球数目
- oracle 删除备份文件两种方式
- POJ-2528-Mayor's posters
- 软件测试理论题目(二)
- python的多重继承
- HDU-2899
- clispse 换主题、皮肤、配色,换黑色主题护眼
- Java web 程序优化例子
- 十大热门CSS3代码生成器
- 最大子矩阵和(dp之路)
- 装船问题