poj2155 树状数组

#include<iostream>
#define maxn 1005
/*
  对于矩形 AB
           CD
      把它分成这样几个区域  B右边 C下边 D 右下边 那么这样update(x,y,1) ,然后处理getsum(x,y) 就是这一点被处理过的次数 ,
      偶数为0,奇数为1
  
  
*/
using namespace std;
int tree[maxn][maxn];
void update(int x,int y,int val)
{
    while(x<=1002)
    {
      int temp=y;
      while(temp<=1002)
      {
        tree[x][temp]+=val;
        temp+=(temp&-temp);
      }
      x+=(x&-x);
    }
}
int getsum(int x,int y)
{
  int sum=0;
  while(x>0)
  {
    int temp=y;
    while(temp>0)
    {
     sum+=tree[x][temp];
     temp-=(temp&-temp);
    }
    x-=(x&-x);
  }
  return sum;
}
int main()
{
    int X;
    int N,T;
    cin>>X;
    while(X--)
    {
      cin>>N>>T;
      memset(tree,0,sizeof(tree));
      for(int i=0;i<T;i++)
      {
        char ch;
        cin>>ch;
        if(ch=='C')
        {
          int x1,y1,x2,y2;
          cin>>x1>>y1>>x2>>y2;
          update(x1,y1,1);
          update(x2+1,y1,1);
          update(x1,y2+1,1);
          update(x2+1,y2+1,1);
        }
        else if(ch=='Q')
        {
          int x1,y1;
          cin>>x1>>y1;
          cout<<(getsum(x1,y1)&1)<<endl;
        }
      }
      cout<<endl;
    }
    system("pause");
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值