zoj 1610 Count the Colors(线段树 区间更新)
来源:互联网 发布:js object 遍历 值 编辑:程序博客网 时间:2024/03/28 17:34
Painting some colored segments on a line, some previously painted segments may be covered by some the subsequent ones.
Your task is counting the segments of different colors you can see at last.
Input
The first line of each data set contains exactly one integer n, 1 <= n <= 8000, equal to the number of colored segments.
Each of the following n lines consists of exactly 3 nonnegative integers separated by single spaces:
x1 x2 c
x1 and x2 indicate the left endpoint and right endpoint of the segment, c indicates the color of the segment.
All the numbers are in the range [0, 8000], and they are all integers.
Input may contain several data set, process to the end of file.
Output
Each line of the output should contain a color index that can be seen from the top, following the count of the segments of this color, they should be printed according to the color index.
If some color can't be seen, you shouldn't print it.
Print a blank line after every dataset.
Sample Input
5
0 4 4
0 3 1
3 4 2
0 2 2
0 2 3
4
0 1 1
3 4 1
1 3 2
1 3 1
6
0 1 0
1 2 1
2 3 1
1 2 0
2 3 0
1 2 1
Sample Output
1 1
2 1
3 1
1 1
0 2
1 1
给一个区间内的线段染色 注意是区间 如把【1,2】区间内染色 只是算一个 总共染n次
问最后能看到颜色的段数 注意是段数!!!
所以要求出所有点中颜色的情况 最后统计颜色出现的段数
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 8010#define MAXM 100010#define INF 99999999#define ll __int64#define bug cout<<"here"<<endl#define fread freopen("ceshi.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;struct node{ int l,r; int col;};node no[MAXN*4];int a[MAXN];int m;void build(int l,int r,int k){ no[k].l=l; no[k].r=r; no[k].col=-1;//-1代表没有颜色或者不是一种颜色 if(l==r) return; int mid=(l+r)/2; build(l,mid,k*2); build(mid+1,r,k*2+1);}void pushdown(int k){ if(no[k].col!=-1) { no[k*2].col=no[k*2+1].col=no[k].col; no[k].col=-1; }}void update(int l,int r,int k,int col){// bug; if(no[k].col==col) return; if(no[k].l>=l&&no[k].r<=r) { no[k].col=col; return; } pushdown(k); int mid=(no[k].l+no[k].r)/2; if(r<=mid) update(l,r,k*2,col); else if(l>mid) update(l,r,k*2+1,col); else { update(l,mid,k*2,col); update(mid+1,r,k*2+1,col); } if((no[k*2].col==no[k*2+1].col)&&(no[k*2].col!=-1)) no[k].col=no[k*2].col;}int cnt[MAXN];void query(int k){// bug; if(no[k].col!=-1) { for(int i=no[k].l;i<=no[k].r;i++) { a[i]=no[k].col; } return; } if(no[k].l==no[k].r) return; query(k*2); query(k*2+1);}void getcnt(){// bug; MEM(cnt,0); int pre=-1; for(int i=0;i<MAXN;i++) { if(pre!=a[i]) { pre=a[i]; cnt[pre]++; } }}int main(){// fread; int n; while(scanf("%d",&n)!=EOF) {// cout<<"n "<<n<<endl; MEM(a,-1); build(0,MAXN,1); m=-1; while(n--) { int l,r,num; scanf("%d%d%d",&l,&r,&num);// cout<<"l "<<l<<" r "<<r<<" "<<num<<endl; if(l==r) continue;// m=max(m,num); r--; update(l,r,1,num);// bug; }// bug; query(1); getcnt(); for(int i=0;i<MAXN;i++) { if(cnt[i]) { printf("%d %d\n",i,cnt[i]); } } puts(""); } return 0;}
- ZOJ 1610 Count the Colors(线段树区间更新)
- zoj 1610 Count the Colors(线段树 区间更新)
- ZOJ 1610Count the Colors 线段树_区间更新
- ZOJ 1610 Count the Colors (线段树区间更新)
- zoj 1610 Count the Colors(线段树 区间更新)
- zoj 1610 Count the Colors 线段树 区间更新
- ZOJ 1610 Count the Colors (线段树区间染色)
- ZOJ 1610 Count the Colors(线段树 区间覆盖)
- ZOJ 1610 Count the Colors (线段树-区间覆盖)
- zoj 1610 Count the Colors (线段树区间覆盖)
- ZOJ 1610 Count the Colors(线段树——区间更新)(成段染色)
- 【线段树区间更新】Count the Colors ZOJ
- zoj 1610 Count the Colors(线段树延迟更新)
- ZOJ 1610Count the Colors 线段树区间染色问题
- ZOJ 1610Count the Colors(线段树+区间染色)
- ZOJ 1610 Count the Colors(线段树区间染色)
- zoj 1610 Count the Colors 线段树区间更新——染色问题
- ZOJ1610 Count the Colors(线段树区间更新)
- 关于要不要为oracle listener设置密码的问题
- C#Connection must be valid and open?
- 1.3.5 head.s开始执行(6)
- Android 学习笔记四:创建工具栏按钮
- hdu4289Control 最大流
- zoj 1610 Count the Colors(线段树 区间更新)
- 项目5——后缀表达式
- github上的安卓开源库汇总
- Android 学习笔记五:支持不同的设备
- MySQL学习笔记20151007数据类型主键外键多对多设计思想
- hdu4768Flyer 二分
- java bind object-c by using bro-gen
- thinkphp-点击量的实现,执行sql用execute()
- request.getRequestURL()和request.getRequestURI()