POJ 2155 Matrix
二维树状数组。。。。
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 15575 | Accepted: 5854 |
Description
We can change the matrix in the following way. Given a rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2), we change all the elements in the rectangle by using "not" operation (if it is a '0' then change it into '1' otherwise change it into '0'). To maintain the information of the matrix, you are asked to write a program to receive and execute two kinds of instructions.
1. C x1 y1 x2 y2 (1 <= x1 <= x2 <= n, 1 <= y1 <= y2 <= n) changes the matrix by using the rectangle whose upper-left corner is (x1, y1) and lower-right corner is (x2, y2).
2. Q x y (1 <= x, y <= n) querys A[x, y].
Input
The first line of each block contains two numbers N and T (2 <= N <= 1000, 1 <= T <= 50000) representing the size of the matrix and the number of the instructions. The following T lines each represents an instruction having the format "Q x y" or "C x1 y1 x2 y2", which has been described above.
Output
There is a blank line between every two continuous test cases.
Sample Input
Sample Output
1
0
0
1
Source
POJ Monthly,Lou Tiancheng
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int tree[][],n,m,t; inline int lowbit(int x)
{
return -x&x;
} void update(int x,int y,int v)
{
int temp=y;
while(x<=n)
{
y=temp;
while(y<=n)
{
tree[x][y]+=v;
y+=lowbit(y);
}
x+=lowbit(x);
}
} int getsum(int x,int y)
{
int sum=;
int temp=y;
while(x>)
{
y=temp;
while(y>)
{
sum+=tree[x][y];
y-=lowbit(y);
}
x-=lowbit(x);
}
return sum;
} int main()
{
scanf("%d",&t);
while(t--)
{
memset(tree,,sizeof(tree));
scanf("%d%d",&n,&m);
n++;char str[];
while(m--)
{
scanf("%s",str);
if(str[]=='C')
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
x1++;y1++;x2++;y2++;
update(x1,y1,);
update(x1,y2+,-);
update(x2+,y1,-);
update(x2+,y2+,);
}
else if(str[]=='Q')
{
int x,y;
scanf("%d%d",&x,&y);
x++;y++;
printf("%d\n",getsum(x,y)&);
}
}
putchar();
}
return ;
}
POJ 2155 Matrix的更多相关文章
- 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 Matrix【二维树状数组+YY(区间计数)】
题目链接:http://poj.org/problem?id=2155 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 ...
- POJ 2155 Matrix (矩形)
date:公元2017年7月19日适逢周三: location:清北集训 杭州 point:二维树状数组/二维差分 Matrix Time Limit: 3000MS Memory Limit: ...
- poj 2155 Matrix (树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16797 Accepted: 6312 Descripti ...
- POJ 2155 Matrix(树状数组+容斥原理)
[题目链接] http://poj.org/problem?id=2155 [题目大意] 要求维护两个操作,矩阵翻转和单点查询 [题解] 树状数组可以处理前缀和问题,前缀之间进行容斥即可得到答案. [ ...
- POJ 2155 Matrix(二维树状数组,绝对具体)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20599 Accepted: 7673 Descripti ...
随机推荐
- Zabbix网络自动发现规则和自动添加hosts及link模板
Version: zabbix 3.0 一.配置网络发现规则 Device uniqueness criteria:选择主机名作为唯一标识(Configuation Hosts中显示的NAME) 二. ...
- 缺陷管理系统mantisbt环境搭建
mantisbt 搭载在lamp环境下 <VirtualHost *:8000> DocumentRoot "/data/mantisbt" </VirtualH ...
- Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
今天执行:autoreconf -fvi的时候出现如下错误: autoreconf: Entering directory `.' autoreconf: configure.in: not usin ...
- Scala高阶函数示例
object Closure { def function1(n: Int): Int = { val multiplier = (i: Int, m: Int) => i * m multip ...
- POJ 3468 A Simple Problem with Integers(线段树/区间更新)
题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Description Yo ...
- wireshark过滤语法总结-重点偏移过滤
http://chenjiji.com/post/3371.html 作者: CHAN | 发布: 2013 年 10 月 24 日 做应用识别这一块经常要对应用产生的数据流量进行分析. 抓包采用wi ...
- Vector & ArrayList 的主要区别
1) 同步性:Vector是线程安全的,也就是说是同步的 ,而ArrayList 是线程序不安全的,不是同步的 数2. 2)数据增长:当需要增长时,Vector默认增长为原来一倍 ,而ArrayLis ...
- vmware下linux系统的安装过程
虚拟机VMware下CentOS6.6安装教程图文详解 [日期:2016-05-24] 来源:Linux社区 作者:Sungeek [字体:大 中 小] 分享下,虚拟机VMware下CentOS ...
- 一个C#解决方案中各文件夹存放了些什么
在VS2015中"生成"(Build)的过程: Source Code(.cs) -> Compile -> Object File(intermediate file ...
- winform 窗体传值
在Form1中:我们要把一个文本传递给Form2窗体,假定为passText public string passText { ...