POJ 2528
来源:互联网 发布:希捷备份软件 编辑:程序博客网 时间:2024/05/21 20:25
/*Mayor's posters线段树区间覆盖离散化特殊数据:131 101 46 10输出:3*/#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define lson (pos<<1)#define rson (pos<<1|1)const int maxn = 55555;int lx[maxn],rx[maxn],vis[maxn];int n,Hash[maxn * 2],cnt,ans;int cover[maxn << 2];void Hash_Init(){ sort(Hash,Hash + cnt); cnt = unique(Hash,Hash + cnt) - Hash; int m = cnt; for(int i = 1; i < cnt; i++) if(Hash[i] != Hash[i - 1] + 1){ Hash[m++] = Hash[i - 1] + 1; } cnt = m; sort(Hash,Hash + cnt); cnt = unique(Hash,Hash + cnt) - Hash;}int HASH(int t){ return lower_bound(Hash,Hash + cnt,t) - Hash;}void build(){ memset(cover,-1,sizeof(cover)); memset(vis,0,sizeof(vis));}void pushdown(int pos){ if(cover[pos] != -1){ cover[lson] = cover[rson] = cover[pos]; cover[pos] = -1; }}void update(int L,int R,int l,int r,int pos,int d){ if(l <= L && R <= r){ cover[pos] = d; return; } pushdown(pos); int mid = (L + R) >> 1; if(l <= mid) update(L,mid,l,r,lson,d); if(r > mid) update(mid + 1,R,l,r,rson,d);}void query(int l,int r,int pos){ if(cover[pos] != -1){ if(!vis[cover[pos]]){ vis[cover[pos]] = 1; ans ++; } return; } if(l == r) return; pushdown(pos); int mid = (l + r) >> 1; query(l,mid,lson); query(mid + 1,r,rson);}int main(){ int T; scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i = 0; i < n; i++){ scanf("%d%d",&lx[i],&rx[i]); Hash[cnt++] = lx[i]; Hash[cnt++] = rx[i]; } Hash_Init(); build(); ans = 0; int ret = 0; for(int i = 0; i < n; i++){ int l = HASH(lx[i]),r = HASH(rx[i]); update(0,cnt,l,r,1,ret++); } query(0,cnt,1); printf("%d\n",ans); } return 0;}
0 0
- POJ 2528
- poj 2528
- POJ 2528
- POJ 2528
- poj 2528
- poj 2528
- poj 2528
- poj 2528
- POJ 2528
- POJ 2528
- poj 2528
- poj-2528
- poj 2528
- poj 2528
- POJ 2528
- poj 2528
- POJ 2528
- POJ 2528
- MyEclipse 安装Spket (支持Extjs4.1.1及jQuery1.8)
- Android锁屏修改
- 比较常用的sql语句
- 第八周 课后实践:项目二——Time类中的运算符重载
- 安卓解析xml格式字符串
- POJ 2528
- ImageView和TextView的background点击效果
- Java基础:异常
- java权限修饰符
- Android中判断当前网络是否可用
- 第一次使用markdown,谈谈我的看法
- java常量池
- IP简介2
- c#中使用npoi将datagridview中的全部数据导出到excel中去