poj 2155
二维树状数组
给出矩阵左上角和右下角坐标,矩阵里的元素 1变0 ,0 变1,然后给出询问,问某个点是多少。
树状数组下标不能为0
二维的每次更新都是从(1,1)到(x,y)
要更新(x1,y1)到(x2,y2)的
update(x2,y2);
update(x2,y1-1);
update(x1-1,y2);
update(x1-1,y1-1);
sum%2==1 时为1。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 1005
int arr[N][N],ans[N];
int lowbit(int x){ return x&-x; }
void update(int x1,int y1)
{
int i,j,sum=0;
for(i=x1;i<N;i+=lowbit(i))
for(j=y1;j<N;j+=lowbit(j))
{
arr[i][j]++;
}
}
int getsum(int x1,int y1)
{
int i,j,sum=0;
for(i=x1;i>0;i-=lowbit(i))
for(j=y1;j>0;j-=lowbit(j))
sum+=arr[i][j];
return sum;
}
int main()
{
int n,m,t,i,j,k,ans,kk;
int x1,y1,x2,y2;
char c;
scanf("%d",&n);
kk=0;
while(n--)
{
if(kk) printf("\n");
scanf("%d%d",&m,&t);
memset(arr,0,sizeof(arr));
for(i=0;i<t;i++)
{
getchar();
scanf("%c",&c);
if(c=='C')
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1++;y1++;x2++;y2++;
update(x2,y2);
update(x2,y1-1);
update(x1-1,y2);
update(x1-1,y1-1);
}
else
{
scanf("%d%d",&x1,&y1);
printf("%d\n",getsum(x1,y1)%2);
}
}
kk=1;
}
return 0;
}
poj 2155的更多相关文章
- POJ 2155 D区段树
POJ 2155 D区段树 思考:D区段树是每个节点设置一个段树树. 刚開始由于题目是求A[I,J],然后在y查询那直接ans^=Map[i][j]的时候没看懂.后面自己把图画出来了才理解. 由于仅 ...
- POJ poj 2155 Matrix
题目链接[http://poj.org/problem?id=2155] /* poj 2155 Matrix 题意:矩阵加减,单点求和 二维线段树,矩阵加减,单点求和. */ using names ...
- POJ 2155 Matrix (D区段树)
http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1 ...
- poj 2155(未完成)
线段树套线段树模板题 链接:http://poj.org/problem?id=2155 题解: 代码: #include <bits/stdc++.h> using namespace ...
- POJ 2155 Matrix【二维树状数组+YY(区间计数)】
题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- POJ 2155 Matrix(树状数组+容斥原理)
[题目链接] http://poj.org/problem?id=2155 [题目大意] 要求维护两个操作,矩阵翻转和单点查询 [题解] 树状数组可以处理前缀和问题,前缀之间进行容斥即可得到答案. [ ...
- 【树状数组】POJ 2155 Matrix
附一篇经典翻译,学习 树状数组 http://www.hawstein.com/posts/binary-indexed-trees.html /** * @author johnsondu * @ ...
- POJ 2155 Matrix
二维树状数组.... Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- poj 2155:Matrix(二维线段树,矩阵取反,好题)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17880 Accepted: 6709 Descripti ...
- POJ 2155 Matrix (二维线段树)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17226 Accepted: 6461 Descripti ...
随机推荐
- CSS截取字符串
/*溢出的字...处理*/ .updatecsssubstring { text-overflow: ellipsis; -o-text-overflow: ellipsis; white-space ...
- Mysql 如何做双机热备和负载均衡 (方法二)
先简要介绍一下mysql双向热备:mysql从3.23.15版本以后提供数据库复制功能.利用该功能可以实现两个数据库同步,主从模式(A->B),互相备份模式(A<=>B)的功能. m ...
- IE8,9下的ajax缓存问题
最近在做一个网站的登录注册框,前端使用了jquery.由于sign和login不是在单独的页面上,而是以一个弹出框出现.所以决定使用ajax来实现注册和登录功能.本以为可以一帆风顺,结果在测试的时候发 ...
- fiddler--手机https
1.访问fiddler的主讲加端口,比如我的是:http://192.168.1.103:8080 在点击fiddlerroot certificate 下载安装证书即可
- java 线程学习
转载:详见处http://lavasoft.blog.51cto.com/62575/27069 Java多线程编程总结 下面是Java线程系列博文的一个编目: Java线程:概念与原理 ...
- windows理论基础(一)
windows体系结构 一. 用户模式和内核模式 (user mode &kernel mode) Intel x86 处理器的体系结构定义了四种特权级,或特为四个环.来保护系统代码不会被低 ...
- delphi如何获得当前操作系统语言环境
function GetWindowsLanguage: string; var WinLanguage: ..] of char; begin VerLanguageName(GetSystemDe ...
- Javascript数组的声明
var cars=new Array(); cars[0]="Audi"; cars[1]="BMW"; cars[2]="Volvo"; ...
- VS EF Error: Configuration Error extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider"
错误截图: Configuration Error :<add extension=".edmx" type="System.Data.Entity.Design. ...
- $timeout, $interval
$timeout, $interval layout: posttitle: Angular@1.4.3 中文 API 服务篇 $timeout & $intervaldesc: '$ti ...