分析

好博客

区间修改,单点查询的题,可以用经典的树状数组的转化,把它化为单点修改,区间查询。

方法是在一些点上加1,最后查询单点的前缀和模2即为答案。相当于维护的是一个异或差分,利用了容斥。

可对查询的前缀矩阵对翻转矩阵的覆盖情况分类讨论须要在哪些点上加1。

最后发现若翻转子矩阵\((x_1,y_1)\rightarrow(x_2,y_2)\),只须在\((x_1,y_1),(x_1,y_2+1),(x_2+1,y_1),(x_2+1,y_2+1)\)这些点上加1,即可满足我们的需要。

代码

#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#pragma GCC optimize ("O0")
using namespace std;
template<class T> inline T read(T&x)
{
T data=0;
int w=1;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
data=10*data+ch-'0',ch=getchar();
return x=data*w;
}
typedef long long ll;
const int INF=0x7fffffff; const int MAXN=1123;
int a[MAXN][MAXN],n; int lowbit(int x)
{
return x&-x;
} void add(int x,int y,int v)
{
for(int i=x;i<=n;i+=lowbit(i))
for(int j=y;j<=n;j+=lowbit(j))
a[i][j]+=v;
} int sum(int x,int y)
{
int res=0;
for(int i=x;i;i-=lowbit(i))
for(int j=y;j;j-=lowbit(j))
res+=a[i][j];
return res;
} int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T;
read(T);
while(T--)
{
int m;
read(n);read(m);
memset(a,0,sizeof(a));
while(m--)
{
char opt[2];
scanf("%s",opt);
if(opt[0]=='C')
{
int x1,y1,x2,y2;
read(x1);read(y1);read(x2);read(y2);
add(x1,y1,1);
add(x1,y2+1,1);
add(x2+1,y1,1);
add(x2+1,y2+1,1);
}
else
{
int x,y;
read(x);read(y);
printf("%d\n",sum(x,y)%2);
}
}
if(T)
puts("");
}
// fclose(stdin);
// fclose(stdout);
return 0;
}

Hint

多组数据一定要初始化数组。

POJ2155 Matrix的更多相关文章

  1. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  2. POJ2155:Matrix(二维树状数组,经典)

    Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...

  3. poj----2155 Matrix(二维树状数组第二类)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 16950   Accepted: 6369 Descripti ...

  4. POJ2155 Matrix 【二维线段树】

    题目链接 POJ2155 题解 二维线段树水题,蒟蒻本想拿来养生一下 数据结构真的是有毒啊,, TM这题卡常 动态开点线段树会TLE[也不知道为什么] 直接开个二维数组反倒能过 #include< ...

  5. POJ2155 Matrix(二维树状数组||区间修改单点查询)

    Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row an ...

  6. POJ2155 Matrix 【二维树状数组】+【段更新点查询】

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17766   Accepted: 6674 Descripti ...

  7. POJ2155 Matrix二维线段树经典题

    题目链接 二维树状数组 #include<iostream> #include<math.h> #include<algorithm> #include<st ...

  8. [POJ2155]Matrix(二维树状数组)

    题目:http://poj.org/problem?id=2155 中文题意: 给你一个初始全部为0的n*n矩阵,有如下操作 1.C x1 y1 x2 y2 把矩形(x1,y1,x2,y2)上的数全部 ...

  9. POJ2155 Matrix 二维线段树

    关键词:线段树 二维线段树维护一个 维护一个X线段的线段树,每个X节点维护一个 维护一个Y线段的线段树. 注意,以下代码没有PushDownX.因为如果要这么做,PushDownX时,由于当前X节点的 ...

随机推荐

  1. spring boot 启动报错(spring-boot-devtools热部署后):The elements [spring.resources.cache-period] were left unbound. Update your application's configuration

    详细错误代码: *************************** APPLICATION FAILED TO START *************************** Descript ...

  2. 转:Too many systemd: Created slice !

    OS: centos-release-7-4.1708 /va/log/message  大量这种提示信息: resolvent: Here is how I got rid of these: vi ...

  3. IE6不兼容hover已解决

    新建一个csshover.htc文件,一下是csshover.htc内容 <public:attach event="ondocumentready" onevent=&qu ...

  4. Please, another Queries on Array? CodeForces - 1114F (线段树,欧拉函数)

    这题刚开始看成求区间$\phi$和了........先说一下区间和的做法吧...... 就是说将题目的操作2改为求$(\sum\limits_{i=l}^{r}\phi(a[i]))\%P$ 首先要知 ...

  5. Python基础--文件操作和集合

    这篇博客来说一下python对文件的操作. 对文件的操作分三步: 1.打开文件获取文件的句柄,句柄就理解为这个文件 2.通过文件句柄操作文件 3.关闭文件. 现有以下文件file.txt: 我们哭了 ...

  6. poj2417 Discrete Logging BSGS裸题

    给a^x == b (mod c)求满足的最小正整数x, 用BSGS求,令m=ceil(sqrt(m)),x=im-j,那么a^(im)=ba^j%p;, 我们先枚举j求出所有的ba^j%p,1< ...

  7. Java中HashMap的实现原理

    最近面试中被问及Java中HashMap的原理,瞬间无言以对,因此痛定思痛觉得研究一番. 一.Java中的hashCode和equals 1.关于hashCode hashCode的存在主要是用于查找 ...

  8. python-day68--模型层基础(model)

    一.ORM : object relationship mapping   对象映射关系 映射关系: 表名 <-------> 类名 字段 <-------> 属性 表记录 & ...

  9. C++技能重拾

    0.虽然静态成员函数不存在this指针,但还是不能在一个class里声明同名同参的虚函数和静态成员函数. 1.vftable里一个虚函数表是一个指针 2.delete本质,调用析构函数同时释放内存Ob ...

  10. cas 服务端相关配置

    SSO-安全证书配置 CAS默认使用的是HTTPS协议,如果对安全要求不高,可以使用HTTP协议 修改deployerConfigContext.xml(cas/WEB-INF)增加参数 p:requ ...