线段树之POJ2528 Mayor's posters
来源:互联网 发布:淘宝网店管理制度 编辑:程序博客网 时间:2024/06/05 16:03
成段替换。
个人认为这题重点是离散化。渣渣也是参考别人题解的,所以不班门弄斧了。
#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#include <limits.h>#include <math.h>#include <algorithm>#include <stack>#include <queue>#include <vector>#include <map>#include <string>#include <sstream>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef long long LL;const double pi=4.0*atan(1.0);const int MAXN=100005;int add[MAXN<<2];struct node{int x,y;};node poster[MAXN];int lisan[MAXN<<2];int biaoji[MAXN];void PushDown(int rt,int len){if(add[rt]){add[rt<<1]=add[rt];add[rt<<1|1]=add[rt];add[rt]=0;}}void build(int l,int r,int rt){add[rt]=0;if(l==r){return ;}int m=(l+r)>>1;build(lson);build(rson);}void update(int L,int R,int c,int l,int r,int rt){if(L<=l && r<=R){add[rt]=c;return ;}PushDown(rt,r-l+1);int m=(l+r)>>1;if(L<=m)update(L,R,c,lson);if(m<R)update(L,R,c,rson);}int ans;void query(int l,int r,int rt){if(add[rt]){if(biaoji[add[rt]]==0){ans++;biaoji[add[rt]]=1;}return ;}if(l==r)return ;int m=(l+r)>>1;query(lson);query(rson);}int lower(int x,int y,int k){int m;while(x<y){m=(x+y)/2;if(lisan[m]>=k)//改成<=可以求递减序列y=m;elsex=m+1;}return x;}int main(){int n,m;int i,j,k;int x,y;int T;while(scanf("%d",&T)!=EOF){while(T--){scanf("%d",&n);k=0;for(i=1;i<=n;i++){scanf("%d%d",&poster[i].x,&poster[i].y);lisan[k++]=poster[i].x;lisan[k++]=poster[i].y;}sort(lisan,lisan+k);k=unique(lisan,lisan+k)-lisan;for(i=k-1;i>0;i--){if(lisan[i]-lisan[i-1]>1){lisan[k++]=lisan[i]-1;}}sort(lisan,lisan+k);memset(biaoji,0,sizeof(biaoji));build(1,k,1);for(i=1;i<=n;i++){int nx=lower(0,k,poster[i].x);int ny=lower(0,k,poster[i].y);update(nx+1,ny+1,i,1,k,1);}ans=0;query(1,k,1);printf("%d\n",ans);}}return 0;}
0 0
- 线段树之POJ2528 Mayor's posters
- Poj2528 Mayor's posters (线段树)
- poj2528 Mayor's posters 【线段树】
- POJ2528 Mayor's posters线段树
- POJ2528 Mayor's posters 线段树
- Mayor's posters poj2528 线段树
- POJ2528 Mayor's posters(线段树)
- 线段树 poj2528 Mayor's posters
- 【POJ2528】Mayor's posters ||【NYOJ9】 (线段树)
- POJ2528:Mayor's posters(线段树区间更新+离散化)
- poj2528--Mayor's posters(线段树+离散化)
- poj2528 Mayor's posters(线段树+离散化)
- poj2528 Mayor's posters,线段树,离散化
- poj2528 Mayor's posters(线段树,离散化)
- poj2528 Mayor’s posters 线段树+离散化
- Mayor's posters(线段树+离散化POJ2528)
- POJ2528 Mayor's posters 线段树区间更新+离散化
- poj2528 Mayor's posters 线段树+离散化
- NSThread
- 早期学习写壳代码
- 使用系统自带的ContentProvider查询联系人
- springmvc配置
- 我的世界史蒂夫——熊孩子版
- 线段树之POJ2528 Mayor's posters
- 解禁 MAVEN “Plugin execution not covered by lifecycle configuration” 问题
- leetcode 113 —— Path Sum II
- Axis2插件的安装以及代码生成
- Apache 模块介绍
- 多线程理论
- HDOJ 1686 Oulipo (KMP)
- A + B高精度
- Cacti的配置详解(一)——使用rrdtool绘图