Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 27655 | Accepted: 8263 |
Description
Input
Output
Sample Input
2 2 4 C 1 1 2 P 1 2 C 2 2 2 P 1 2
Sample Output
2 1
Source
题意:整段区间染色
code:
1 #include<iostream> 2 using namespace std; 3 4 int l,t,o; 5 6 struct Node 7 { 8 int l,r; 9 int col; 10 }; 11 struct Node node[100010*4]; 12 13 void build(int left,int right,int cur=1) 14 { 15 node[cur].l=left; 16 node[cur].r=right; 17 node[cur].col=0; 18 if(left==right) 19 return; 20 int mid=(left+right)/2; 21 build(left,mid,cur*2); 22 build(mid+1,right,cur*2+1); 23 } 24 25 void update(int left,int right,int col,int cur=1) 26 { 27 if(left<=node[cur].l&&right>=node[cur].r) 28 { 29 node[cur].col=col; 30 return; 31 } 32 if(node[cur].col>0) 33 { 34 node[cur*2].col=node[cur*2+1].col=node[cur].col; 35 node[cur].col=0; 36 } 37 int mid=(node[cur].l+node[cur].r)/2; 38 if(left>mid) 39 update(left,right,col,cur*2+1); 40 else if(right<=mid) 41 update(left,right,col,cur*2); 42 else 43 { 44 update(left,mid,col,cur*2); 45 update(mid+1,right,col,cur*2+1); 46 } 47 } 48 49 bool vst[40]; 50 int query(int left,int right,int cur=1) 51 { 52 int sum=0; 53 if(node[cur].col) 54 { 55 if(!vst[node[cur].col]) 56 { 57 sum++; 58 vst[node[cur].col]=true; 59 } 60 return sum; 61 } 62 int mid=(node[cur].l+node[cur].r)/2; 63 if(left>mid) 64 sum+=query(left,right,cur*2+1); 65 else if(right<=mid) 66 sum+=query(left,right,cur*2); 67 else 68 { 69 sum+=query(left,right,cur*2); 70 sum+=query(left,right,cur*2+1); 71 } 72 return sum; 73 } 74 75 int main() 76 { 77 scanf("%d%d%d",&l,&t,&o); 78 build(1,l); 79 node[1].col=1; 80 while(o--) 81 { 82 int a,b; 83 char ch; 84 getchar(); 85 scanf("%c%d%d",&ch,&a,&b); 86 if(a>b) 87 { 88 int temp=a; 89 a=b; 90 b=temp; 91 } 92 if(ch=='C') 93 { 94 int c; 95 scanf("%d",&c); 96 update(a,b,c); 97 } 98 else 99 { 100 memset(vst,false,sizeof(vst)); 101 printf("%d\n",query(a,b)); 102 } 103 } 104 return 0; 105 }