楼教主的题,很不错的二维树状数组
#include <map> #include <set> #include <list> #include <stack> #include <queue> #include <cmath> #include <ctime> #include <cstdio> #include <vector> #include <sstream> #include <cstdlib> #include <complex> #include <cstring> #include <iostream> #include <algorithm> #define REP(i,N) for (int i = 0;i < (N);i++) #define REP_1(i,N) for (int i = 1;i < (N);i++) #define REP_2(i,be,en) for (int i = (be);i < (en);i++) #define DWN(i,N) for (int i = (N);i >= 0;i--) #define DWN_1(i,N) for (int i = (N);i >= 1;i--) #define DWN_2(i,en,be) for (int i = (en);i >= (be);i--) #define FR(N) freopen((N),"r",stdin) #define FW(N) freopen((N),"w",stdout) #define MAXN 1010 #define GETS(ch) fgets((ch),MAXN,stdin) #define INF 0x3f3f3f3f #define MOD 1000000007 using namespace std; typedef long long LL; typedef map<int,LL> MINT; typedef map<char,int> MCH; typedef map<string,int> MSTR; typedef vector<int> VINT; typedef set<LL> SINT; typedef pair<int,int> PINT; LL read(){ LL ret=0,f=1; char x=getchar(); while(!(x>=‘0‘ && x<=‘9‘)){if(x==‘-‘)f=-1;x=getchar();} while(x>=‘0‘ && x<=‘9‘) ret=ret*10+x-‘0‘, x=getchar(); return ret*f; } int c[MAXN][MAXN]; int N; int lowbit(int x) { return x & (-x); } int Query(int x,int y) { int ans = 0; for (int i = x;i > 0;i -= lowbit(i)) { for (int j = y;j > 0;j -= lowbit(j)) { ans += c[i][j]; } } return ans % 2 == 0 ? 0 : 1; } void Updata(int x,int y,int value) { for (int i = x;i <= N;i += lowbit(i)) { for (int j = y;j <= N;j += lowbit(j)) { c[i][j] += value; } } } int main() { //FR("1.txt"); int T; cin >> T; while (T--) { memset(c,0,sizeof(c)); int X; cin >> N >> X; getchar(); REP(i,X) { char c = getchar(); if (c == ‘C‘) { int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; getchar(); Updata(x1,y1,1); Updata(x1,y2 + 1,1); Updata(x2 + 1,y1,1); Updata(x2 + 1,y2 + 1,1); } else if (c == ‘Q‘) { int x,y; cin >> x >> y; getchar(); cout << Query(x,y) << endl; } } cout << endl; } }
时间: 2024-11-05 03:21:38