zoj 1610 Count the Colors
2012-02-27 17:52
387 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=610
View Code
View Code
#include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <cstring> #include <string> #include <algorithm> #include <queue> #include <stack> #include <climits> #define L(x) (x << 1) #define R(x) (x << 1 | 1) using namespace std; const int MAX = 8010; struct Tnode{ int col; int l,r;}; Tnode node[MAX*4]; int col[MAX],len[MAX];; void init() { memset(node,0,sizeof(node)); memset(col,-1,sizeof(col)); } void Build(int t,int l,int r) { node[t].l = l; node[t].r = r; node[t].col = -1; if( l == r - 1 ) return ; int mid = ( l + r ) >> 1; Build(L(t), l, mid); Build(R(t), mid, r); } void Updata(int t,int l,int r,int col) { if( node[t].l >= l && node[t].r <= r ) { node[t].col = col; return ; } if( node[t].col == col ) return ; if( node[t].col >= 0 ) { node[R(t)].col = node[t].col; node[L(t)].col = node[t].col; node[t].col = -1; } int mid = (node[t].l + node[t].r) >> 1; if( l >= mid ) Updata(R(t),l,r,col); else if( r <= mid ) Updata(L(t),l,r,col); else { Updata(L(t),l,mid,col); Updata(R(t),mid,r,col); } } void Compute(int t,int l,int r) { if( node[t].col >= 0 ) { for(int i=l; i<r; i++) col[i] = node[t].col; return ; } if( node[t].l == node[t].r - 1 ) return ;// 如果父亲节点已经是这种颜色了,就没必要再染色了 int mid = (node[t].l + node[t].r) >> 1; if( l >= mid ) Compute(R(t),l,r); else if( r <= mid ) Compute(L(t),l,r); else { Compute(L(t),l,mid); Compute(R(t),mid,r); } } int main() { int n,x,y,color; while( ~scanf("%d",&n) ) { init(); Build(1,0,8000); while( n-- ) { scanf("%d%d%d",&x,&y,&color); Updata(1,x,y,color); } Compute(1,0,8000); memset(len,0,sizeof(len)); for(int i=0; i<MAX; i++) if( col[i+1] != col[i] && col[i] != -1 ) len[col[i]]++; for(int i=0; i<MAX; i++) if( len[i] ) printf("%d %d\n",i,len[i]); printf("\n"); } return 0; }
相关文章推荐
- 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 (线段树:区间染色set,整体查询)
- 【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(线段树 区间更新)
- 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 【线段树区间更新 + 节点为区间】