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 ...
随机推荐
- zoj 2587 Unique Attack 最小割判定
题目链接 让你判断最小割是否唯一. 判断方法是, 先求一遍最大流, 然后从源点dfs一次, 搜索未饱和边的数目. 从汇点dfs一次, 同样也是搜索未饱和边的数目, 看总和是否等于n. 如果等于n那么唯 ...
- 使用 http://httpbin.org/ 验证代理地址
发现一个很方便的工具,在Linux 下使用 curl http://httpbin.org/ 可以返回当前使用的一些网络信息
- Nancy之实现API
Nancy之实现API的功能 0x01.前言 现阶段,用来实现API的可能大部分用的是ASP.NET Web API或者是ASP.NET MVC,毕竟是微软官方出产的,用的人也多. 但是呢,Nancy ...
- 多线程中Local Store Slot(本地存储槽)
在Java中有一种ThreadLocal机制,为每一个使用该变量的线程都提供一个变量值的副本,是每一个线程都可以独立地改变自己的副本,而不会和其它线程的副本冲突.从线程的角度看,就好像每一个线程都完全 ...
- java单链表代码实现
用惯了C++,java写起来果然不太爽...不废话了,上代码... package javaInnerclassDemo; class Link{ class Node{ private String ...
- Dropping Balls (二叉树+思维)
Dropping Balls A number of K balls are dropped one by one from the root of a fully binary tree st ...
- angularJS使用$watch监控数据模型的变化
使用$watch监控数据模型的变化 在scope 内置的全部函数中,用得最多的可能就是$watch 函数了.当你的数据模型中某一部分发生变化时,$watch 函数能够向你发出通知.你能够监控单个对象的 ...
- 基于最简单的FFmpeg包封过程:视频和音频分配器启动(demuxer-simple)
===================================================== 基于最简单的FFmpeg封装工艺的系列文章上市: 最简单的基于FFmpeg的封装格式处理:视 ...
- SQL Server索引进阶:第八级,唯一索引
原文地址: Stairway to SQL Server Indexes: Level 8,Unique Indexes 本文是SQL Server索引进阶系列(Stairway to SQL Ser ...
- HTML系列(一):创建HTML文档
从本学期开始我打算把我以前学的知识点系统地总结一下,先从HTML开始.(本系列内容总结自博文视点出版社•代码逆袭系列书籍,包括代码片段.) 一.HTML文档类型 HTML版本众多,浏览器如何得知使用的 ...