分析

好博客

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

方法是在一些点上加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. SVN提交文件失败:系统找不到指定路径

    完成程序代码工作后,进行SVN的文件提交.先进行项目的更新,然后在修改的文件上进行提交操作,发现SVN弹出提示信息,“系统找不到指定路径”提交失败,如下图:                       ...

  2. 《图解Http》8: 用户身份认证Cookie管理session; 9:HTTP的追加协议(websoket, webDAV)

    基本认证,(安全等级低,多数网站不使用) Digest认证:(也不怎么用) SSL客户端认证:(凭借客户端证书认证,如网银登陆) 表单认证:用户名/密码.(常用) SSL客户端认证采用two-fact ...

  3. Jersey 2.x 从Maven Archetype 创建一个新项目

    创建 Jersey 工程需要使用 Apache 的 Maven 软件工程和管理工具.所有的Jersey产品模块都可以在 Maven中央库 中找到.这样的话 Jersey 可以非常容易和其他基于 Mav ...

  4. CentOS7 install apache

    1. yum install httpd 2. config /etc/httpd/conf/httpd.conf <VirtualHost *:80>  ServerName www.l ...

  5. hdu-4417-主席树+离线

    Super Mario Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. Scrum介绍——续

    四. Scrum过程 Scrum的过程如图4-1所示 图4-1 Scrum过程 4.1 建立Product Backlog Product Backlog是Product Owner把客户的商业需求按 ...

  7. JavaScript学习总结(十四)——JavaScript编写类的扩展方法

    在​J​a​v​a​S​c​r​i​p​t​中​可以使​用​类的p​r​o​t​o​t​y​p​e属性来​扩​展​类的属​性​和​方​法,在实际开发当中,当JavaScript内置的那些类所提供的动态 ...

  8. hadoop redis install (4)

    reference: http://dblab.xmu.edu.cn/blog/131/    https://github.com/dmajkic/redis   https://blog.csdn ...

  9. Sring类的codePointAt()方法

    工作中遇到一段代码 private static String getClassNameWithoutPackage(Class cl) { String className = cl.getName ...

  10. DevExpress v17.2新版亮点—Bootstrap篇(一)

    用户界面套包DevExpress v17.2日前终于正式发布,本站将以连载的形式为大家介绍各版本新增内容.本文将介绍了Bootstrap Controls v17.2 的CardView.Charts ...