poj 2155 matrix 二维线段树

时间:2021-06-09 03:58:09

题目链接

区间翻转, 单点查询, 查询操作我真是不太明白......

     #include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = ;
int sum[maxn<<][maxn<<], n, ans;
void pushUp(int pos, int rt) {
sum[pos][rt] = sum[pos][rt<<]+sum[pos][rt<<|];
}
void sub_update(int pos, int L, int R, int l, int r, int rt) {
if(L<=l&&R>=r) {
sum[pos][rt]^=;
return ;
}
int m = l+r>>;
if(L<=m)
sub_update(pos, L, R, lson);
if(R>m)
sub_update(pos, L, R, rson);
}
void update(int LX, int RX, int LY, int RY, int l, int r, int rt) {
if(LX<=l&&RX>=r) {
sub_update(rt, LY, RY, , n, );
return ;
}
int m = l+r>>;
if(LX<=m)
update(LX, RX, LY, RY, lson);
if(RX>m)
update(LX, RX, LY, RY, rson);
}
void sub_query(int pos, int p, int l, int r, int rt) {
ans ^= sum[pos][rt];
if(l == r)
return ;
int m = l+r>>;
if(p<=m)
return sub_query(pos, p, lson);
else
return sub_query(pos, p, rson);
}
void query(int x, int y, int l, int r, int rt) {
sub_query(rt, y, , n, );
if(l == r)
return ;
int m = l+r>>;
if(x<=m)
return query(x, y, lson);
else
return query(x, y, rson);
}
int main()
{
int t, q, lx, rx, ly, ry;
cin>>t;
char c[];
while(t--) {
mem(sum);
scanf("%d%d", &n, &q);
while(q--) {
scanf("%s", c);
if(c[] == 'C') {
scanf("%d%d%d%d", &lx, &ly, &rx, &ry);
update(lx, rx, ly, ry, , n, );
} else {
scanf("%d%d", &lx, &ly);
ans = ;
query(lx, ly, , n, );
printf("%d\n", ans);
}
}
if(t)
puts("");
}
}