题意很明确 给你一个图某坐标上的星星亮 暗 条件 求出当前区间内所有亮星星的总数
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 1005;
int tree[maxn + 2][maxn + 2];
inline int Lowbit(int x)
{
return x&(-x);
}
inline void Update(int x,int y,int v)
{
for(int i=x; i<=maxn; i+=Lowbit(i))
for(int j=y; j<=maxn; j+=Lowbit(j))
tree[i][j]+=v;
}
inline int Query(int x,int y)
{
int sum=0;
for(int i=x; i>0; i-=Lowbit(i))
for(int j=y; j>0; j-=Lowbit(j))
sum+=tree[i][j];
return sum;
}
bool map[1005][1005];
int main()
{
int n;
char c[3];
memset(tree,0,sizeof(tree));
memset(map,0,sizeof(map));
cin>>n;
while(n--)
{
scanf("%s",c);
if(c[0]=='B')
{
int x,y;
scanf("%d%d",&x,&y);
if(!map[x+1][y+1])
map[x+1][y+1]=1,Update(x+1,y+1,1);
}
else if(c[0]=='D')
{
int x,y;
scanf("%d%d",&x,&y);
if(map[x+1][y+1]==1)
map[x+1][y+1]=0,Update(x+1,y+1,-1);
}
else if(c[0]=='Q')
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
if(x1>x2) swap(x1,x2);
if(y1>y2) swap(y1,y2);
int ans=Query(x2+1,y2+1)-Query(x1,y2+1)-Query(x2+1,y1)+Query(x1,y1);
printf("%d\n",ans);
}
}
return 0;
}