矩阵的操作

来源:互联网 发布:数据库substr 编辑:程序博客网 时间:2024/06/10 11:07
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;


int sum[1000][1000];
int n,t;
int c(int x)
{   return x&(x^(x-1));
}
void change(int x,int y,int add)
{int ty=y; 
   while(x<=n)
    { y=ty;
     while(y<=n)
     {sum[x][y]=sum[x][y]+add;
       y=y+c(y);
     }
     x=x+c(x);
    }
}
int query(int x,int y)
{  int ans=0;
int ty=y; 
   while(x>0)
    { y=ty;
     while(y>0)
     {ans=sum[x][y]+ans;
       y=y-c(y);
     }
     x=x-c(x);
    }
   return ans;
}
int main()
{ cin>>n>>t;
  for(int i=1;i<=t;i++)
  {int x1,x2,y1,y2;
  char ch; cin>>ch;
  if(ch=='C')
    {cin>>x1>>y1>>x2>>y2;
      change(x1,y1,1);
    change(x1,y2+1,1);
    change(x2+1,y1,1);
     change(x2+1,y2+1,1);
}
else
{ cin>>x1>>y1;
 cout<<(query(x1,y1)&1)<<endl;
}
  
   }
 
return 0;
0 0
原创粉丝点击