Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么会RE 答案都对啊??#include <iostream> using namespace std; const int MAXN = 100000*20; typedef struct { int l,r; int colN;//该区间内的颜色种数 }Tree; Tree tree[MAXN]; void build(int root,int left,int right) { tree[root].l = left; tree[root].r = right; tree[root].colN = 1;//At the beginning, the board was painted in color 1 if( left == right ) return;//叶子 int mid = (left+right)/2; build(root*2,left,mid); build(root*2+1,mid+1,right); } void update(int root,int color) { if( tree[root].l == tree[root].r ) return; tree[root*2].colN = tree[root*2+1].colN = color; update(root*2,color); update(root*2+1,color); } void paint(int root,int left,int right,int color) { if( tree[root].l == left && tree[root].r == right ) { tree[root].colN = color;//完全覆盖 update(root,color); return; } if( tree[root*2].r >= right ) paint(root*2,left,right,color); else if( tree[root*2+1].l <= left ) paint(root*2+1,left,right,color); else { paint(root*2,left,tree[root*2].r,color); paint(root*2+1,tree[root*2+1].l,right,color); } tree[root].colN = tree[root*2].colN | tree[root*2+1].colN; } int query(int root,int left,int right) { int c1,c2; if( tree[root].l == left && tree[root].r == right ) return tree[root].colN; if( tree[root*2].r >= right ) return query(root*2,left,right); else if( tree[root*2+1].l <= left ) return query(root*2,left,right); else { c1 = query(root*2,left,tree[root*2].r); c2 = query(root*2+1,tree[root*2+1].l,right); return (c1 | c2); } } int change(int n) { int ans = 0; while( n > 0 ) { if( n % 2 == 1 ) ans ++; n = n >> 1; } return ans; } int main() { int L,T,O,a,b,c,u; char cmd[3]; //freopen("2777.txt","r",stdin); //freopen("out.txt","w",stdout); while( cin >> L >> T >> O ) { build(1,1,L); while( O -- ) { scanf("%s",cmd); if( cmd[0] == 'C') { scanf("%d %d %d",&a,&b,&c); if( a > b ) {u=a,a=b,b=u;} paint(1,a,b,1<<(c-1)); } else { scanf("%d %d",&a,&b); if( a > b ) {u=a,a=b,b=u;} int ans = query(1,a,b); ans = change(ans); printf("%d\n",ans); } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator