标签:des style blog io ar color os sp for
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 19174 | Accepted: 7207 |
Description
Input
Output
Sample Input
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
Sample Output
1 0 0 1
Note
这是一个二维的树状数组,区间更新,单点查询
#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <algorithm> using namespace std; const int MAX = 1010; int c[MAX][MAX]; int n; int a,b,e,d; int Lowbit(int x) { return x & (-x); } void Updata(int x,int y,int z) { int i,k; for(i=x; i<=n; i+=Lowbit(i)) for(k=y; k<=n; k+=Lowbit(k)) c[i][k]+=z; } int Get(int x,int y) { int i,k,sum = 0; for(i=x; i>0; i-=Lowbit(i)) for(k=y; k>0; k-=Lowbit(k)) sum += c[i][k]; return sum; } int main() { int x; scanf("%d",&x); while(x--) { memset(c,0,sizeof(c)); int q; scanf("%d%d",&n,&q); char s; while(q--) { //cout<<q<<endl; scanf(" %c",&s); if(s==‘C‘) { scanf("%d%d%d%d",&a,&b,&e,&d); a++,b++,e++,d++; Updata(e,d,1); Updata(a-1,d,-1); Updata(e,b-1,-1); Updata(a-1,b-1,1); } if(s==‘Q‘) { scanf("%d%d",&a,&b); printf("%d\n",Get(a,b)%2); } } if(x!=0) printf("\n"); } return 0; }
标签:des style blog io ar color os sp for
原文地址:http://www.cnblogs.com/qscqesze/p/4145383.html