ZOJ 1610 Count the Colors 线段树 染色问题
来源:互联网 发布:淘宝客地推海报 编辑:程序博客网 时间:2024/05/08 23:59
做法:在udate之后可以直接把线段树上的信息映射到一个数组上考虑
#include<cstdio>#include<cstring>#define left l,m,x<<1#define right m+1,r,x<<1|1const int LMT=16002;int cov[LMT<<2],seg[LMT],ans[LMT];//映射法void init(void){memset(cov,-1,sizeof(cov));memset(seg,-1,sizeof(seg));memset(ans,0,sizeof(ans));}void cut(int x){if(cov[x]!=-1){cov[x<<1]=cov[x<<1|1]=cov[x];cov[x]=-1;}}void update(int co,int L,int R,int l,int r,int x){if(L<=l&&r<=R){cov[x]=co;return ;}cut(x);int m=(l+r)>>1;if(L<=m)update(co,L,R,left);if(R>m)update(co,L,R,right);}void query(int l,int r,int x)//线段树射到区间上{if(cov[x]!=-1){int i=l;for(;i<=r;i++)seg[i]=cov[x];return;}if(l==r)return;int m=(l+r)>>1;query(left);query(right);}int main(void){int n,l,r,co,i,j;while(~scanf("%d",&n)){init();for(i=1;i<=n;i++){scanf("%d%d%d",&l,&r,&co);l++;r++;l<<=1;r<<=1;update(co,l,r,1,LMT-1,1);}query(1,LMT-1,1);for(int i=1;i<LMT;)if(seg[i]!=-1){j=i;ans[seg[i]]++;while(j<LMT&&seg[j]==seg[i])j++;i=j;}else i++; for( i=0;i<=8000;i++)if(ans[i])printf("%d %d\n",i,ans[i]);printf("\n");}return 0;}
- ZOJ 1610 Count the Colors 线段树 染色问题
- ZOJ 1610Count the Colors 线段树区间染色问题
- 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 1610Count the Colors//线段树
- zoj 1610 Count the Colors【线段树】
- zoj 1610 Count the Colors[线段树]
- 【线段树】Count the Colors (zoj 1610)
- zoj 1610 Count the Colors(线段树)
- zoj 1610 Count the Colors 线段树
- 指针赋值的问题
- linux出现Cannot set LC_CTYPE to default locale: No such file or directory错误的解决办法
- 设计模式---抽象工厂模式
- T-SQL查询进阶--深入浅出视图
- struts1总结——优缺点
- ZOJ 1610 Count the Colors 线段树 染色问题
- 【强连通】Victoria的舞会2 -- Vijos 1022,1023
- activity全屏设置
- 2013 C++第一周任务-成绩问题(结构体)
- Windows XP系统下架设FTP服务器实例详解
- python打开带有目录的文件的注意事项
- POJ 3277 City Horizon 线段染色
- Windows XP系统下架设FTP服务器实例详解
- 距离和相似度度量