标签:des style blog http color io os ar java
1 2 10 C 2 1 2 2 Q 2 2 C 2 1 2 1 Q 1 1 C 1 1 2 1 C 1 2 1 2 C 1 1 2 2 Q 1 1 C 1 1 2 1 Q 2 1
1 0 0 1
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 1001; 18 struct subtree{ 19 int lt,rt; 20 bool val; 21 }; 22 struct node{ 23 int lt,rt; 24 subtree sb[maxn<<2]; 25 }; 26 node tree[maxn<<2]; 27 int n,m,ans; 28 void sub(int lt,int rt,int v,subtree *sb){ 29 sb[v].lt = lt; 30 sb[v].rt = rt; 31 sb[v].val = false; 32 if(lt == rt) return; 33 int mid = (lt + rt)>>1; 34 sub(lt,mid,v<<1,sb); 35 sub(mid+1,rt,v<<1|1,sb); 36 } 37 void build(int lt,int rt,int v){ 38 tree[v].lt = lt; 39 tree[v].rt = rt; 40 sub(1,n,1,tree[v].sb); 41 if(lt == rt) return; 42 int mid = (lt + rt)>>1; 43 build(lt,mid,v<<1); 44 build(mid+1,rt,v<<1|1); 45 } 46 void subupdate(int lt,int rt,int v,subtree *sb){ 47 if(sb[v].lt >= lt && sb[v].rt <= rt){ 48 sb[v].val ^= 1; 49 return; 50 } 51 if(lt <= tree[v<<1].rt) subupdate(lt,rt,v<<1,sb); 52 if(rt >= tree[v<<1|1].lt) subupdate(lt,rt,v<<1|1,sb); 53 } 54 void update(int lt,int rt,int y1,int y2,int v){ 55 if(tree[v].lt >= lt && tree[v].rt <= rt){ 56 subupdate(y1,y2,1,tree[v].sb); 57 return; 58 } 59 if(lt <= tree[v<<1].rt) update(lt,rt,y1,y2,v<<1); 60 if(rt >= tree[v<<1|1].lt) update(lt,rt,y1,y2,v<<1|1); 61 62 } 63 void subquery(int y,int v,subtree *sb){ 64 ans ^= sb[v].val; 65 if(sb[v].lt == sb[v].rt) return; 66 if(y <= sb[v<<1].rt) subquery(y,v<<1,sb); 67 else subquery(y,v<<1|1,sb); 68 } 69 void query(int x,int y,int v){ 70 subquery(y,1,tree[v].sb); 71 if(tree[v].lt == tree[v].rt) return; 72 if(x <= tree[v<<1].rt) query(x,y,v<<1); 73 else query(x,y,v<<1|1); 74 } 75 int main(){ 76 int t,x1,y1,x2,y2; 77 char s[5]; 78 scanf("%d",&t); 79 while(t--){ 80 scanf("%d %d",&n,&m); 81 build(1,n,1); 82 for(int i = 0; i < m; ++i){ 83 scanf("%s",s); 84 if(s[0] == ‘Q‘){ 85 ans = 0; 86 scanf("%d %d",&x1,&y1); 87 query(x1,y1,1); 88 printf("%d\n",ans); 89 }else if(s[0] == ‘C‘){ 90 scanf("%d %d %d %d",&x1,&y1,&x2,&y2); 91 update(x1,x2,y1,y2,1); 92 } 93 } 94 puts(""); 95 } 96 return 0; 97 }
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/crackpotisback/p/4014495.html