poj 2155 B - Matrix 二维树状数组

#include<iostream>
#include<string>
#include<string.h>
#include<cstdio>
using namespace std;
const int maxn=;
int n;
int c[maxn][maxn];
int lowbit(int x) { return x&(-x); }
void update(int x,int y)
{
for(int i = x; i; i -= lowbit(i))
for(int j = y; j; j -= lowbit(j))
++c[i][j];
}
int query(int x, int y)
{
int sum = ;
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= n; j+= lowbit(j))
sum += c[i][j];
return sum;
}
int main()
{
int T; cin>>T;
while(T--)
{
memset(c,,sizeof(c));
int x; cin>>n>>x;
while(x--)
{
char s; cin>>s;
int a,b,c,d;
if(s == 'C')
{
cin>>a>>b>>c>>d;
update(c, b-);
update(a-, d);
update(a-, b-);
update(c, d);
}
else{cin>>a>>b; cout<<(query(a, b) & ? "" : "")<<endl; }
}
puts("");
}
}
上一篇:objectarx之判断给定的三点是否共线


下一篇:ndk的一些概念