题目链接

二维树状数组

给出矩阵左上角和右下角坐标,矩阵里的元素 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的更多相关文章

  1. POJ 2155 D区段树

    POJ 2155  D区段树 思考:D区段树是每个节点设置一个段树树. 刚開始由于题目是求A[I,J],然后在y查询那直接ans^=Map[i][j]的时候没看懂.后面自己把图画出来了才理解. 由于仅 ...

  2. POJ poj 2155 Matrix

    题目链接[http://poj.org/problem?id=2155] /* poj 2155 Matrix 题意:矩阵加减,单点求和 二维线段树,矩阵加减,单点求和. */ using names ...

  3. POJ 2155 Matrix (D区段树)

    http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 1 ...

  4. poj 2155(未完成)

    线段树套线段树模板题 链接:http://poj.org/problem?id=2155 题解: 代码: #include <bits/stdc++.h> using namespace ...

  5. POJ 2155 Matrix【二维树状数组+YY(区间计数)】

    题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  6. POJ 2155 Matrix(树状数组+容斥原理)

    [题目链接] http://poj.org/problem?id=2155 [题目大意] 要求维护两个操作,矩阵翻转和单点查询 [题解] 树状数组可以处理前缀和问题,前缀之间进行容斥即可得到答案. [ ...

  7. 【树状数组】POJ 2155 Matrix

    附一篇经典翻译,学习 树状数组  http://www.hawstein.com/posts/binary-indexed-trees.html /** * @author johnsondu * @ ...

  8. POJ 2155 Matrix

    二维树状数组....                          Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  9. poj 2155:Matrix(二维线段树,矩阵取反,好题)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17880   Accepted: 6709 Descripti ...

  10. POJ 2155 Matrix (二维线段树)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17226   Accepted: 6461 Descripti ...

随机推荐

  1. scanf函数和printf函数

    C程序实现输出和输入的 主要是printf函数 和 scanf函数,这两个函数是格式输入输出 格式声明由%和格式字符组成 如%d,%f 格式字符:  d格式符:用来输出一个有符号的十进制整数  c格式 ...

  2. aJax学习之Ajax工作原理

    转自:http://www.cnblogs.com/mingmingruyuedlut/archive/2011/10/18/2216553.html 在写这篇文章之前,曾经写过一篇关于AJAX技术的 ...

  3. 网络子系统48_ip协议数据帧的发送

    //ip协议与l4协议接口,l4通过此接口向下l3传递数据帧 //函数主要任务: // 1.通过路由子系统路由封包 // 2.填充l3报头 // 3.ip分片 // 4.计算校验和 // 5.衔接邻居 ...

  4. R与数据分析旧笔记(十六) 基于密度的方法:DBSCAN

    基于密度的方法:DBSCAN 基于密度的方法:DBSCAN DBSCAN=Density-Based Spatial Clustering of Applications with Noise 本算法 ...

  5. perl正则表达式第二周笔记

    1.使用正则表达式修改文本 1.使用正则表达式修改文本 正则表达式的功能不只有查询,还可以对文本进行修改,例如替换 $var=~m/regex/i $var=~s/regex/replacement/ ...

  6. 安卓里面JSON处理和JAVA SE里面的JSON包

    今天编译安卓项目遇到这个问题 com.android.dex.DexException: Multiple dex files define的解决办法 大致意思就是引用了 相同的包 在JAVA SE里 ...

  7. CSS background-repeat 属性

    ###起因 >今天遇到一个问题,就是在给一个元素设置width 属性为100% 之后, 鼠标放上去之后,仍然只有部分是阴影状态,如下图所示: --- 经过一番思索,这TM 不就是,hover 上 ...

  8. pyhton

    http://panda.www.net.cn/cgi-bin/check.cgi?area_domain= http://whois.chinaz.com/ beautifulsoup4 impor ...

  9. td之overflow:hidden 多余文本隐藏效果

    td之overflow:hidden 多余文本隐藏效果 方法1: table-layout: fixed; width: 200px; 语法: table-layout : auto | fixed ...

  10. setFocus一定要写在setLayout设置的后面,否则不起作用——使用setFocusPolicy为控件设置不同的焦点策略:Tab焦点,Click焦点,Wheel焦点和没有焦点

    QLineEdit* pEditor = new QLineEdit(m_strText);    pEditor->resize(.......);    pEditor->move(. ...