Matrix 二维树状数组的第二类应用
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 17976 | Accepted: 6737 |
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
1
2 10
C 2 1 2 2
Q 2 2
C 2 1 2 1
Q 1 1
C 1 1 2 1
C 1 2 1 2
C 1 1 2 2
Q 1 1
C 1 1 2 1
Q 2 1
Sample Output
1
0
0
1
#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int ms=1e3+;
int map[ms][ms];
int n,m;
int lowbit(int t)
{
return t&(-t);
}
void updata(int x,int y,int d)
{
while(x>)
{
int y1=y;
while(y1>)
{
map[x][y1]+=d;
y1-=lowbit(y1);
}
x-=lowbit(x);
}
}
int getsum(int x,int y)
{
int sum=;
while(x<=n)
{
int y1=y;
while(y1<=n)
{
sum+=map[x][y1];
y1+=lowbit(y1);
}
x+=lowbit(x);
}
return sum;
}
int main()
{
int i,j,k,t,tcase;
//#ifndef oo
//cout<<"dkkjdkk"<<endl;
//#endif
cin>>tcase;
while(tcase--)
{
cin>>n>>m;
memset(map,,sizeof(map));
char s[];//避免回车符的影响 否则 getchar()
while(m--)
{
cin>>s;
if(s[]=='C')
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
updata(x2,y2,);
updata(x1-,y2,-);
updata(x1-,y1-,);
updata(x2,y1-,-);
//updata(x1-1,y1-1,1);
}
else if(s[]=='Q')
{
int x,y;
cin>>x>>y;
cout<<getsum(x,y)%<<endl;
}
}
if(tcase)
cout<<endl;
}
return ;
}
Matrix 二维树状数组的第二类应用的更多相关文章
- [poj2155]Matrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25004 Accepted: 9261 Descripti ...
- 【poj2155】Matrix(二维树状数组区间更新+单点查询)
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- POJ 2155 Matrix(二维树状数组,绝对具体)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20599 Accepted: 7673 Descripti ...
- POJ 2155:Matrix 二维树状数组
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 21757 Accepted: 8141 Descripti ...
- poj 2155 Matrix (二维树状数组)
题意:给你一个矩阵开始全是0,然后给你两种指令,第一种:C x1,y1,x2,y2 就是将左上角为x1,y1,右下角为x2,y2,的这个矩阵内的数字全部翻转,0变1,1变0 第二种:Q x1 y1,输 ...
- poj----2155 Matrix(二维树状数组第二类)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16950 Accepted: 6369 Descripti ...
- POJ2155:Matrix(二维树状数组,经典)
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- Matrix (二维树状数组)
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- poj 2155 B - Matrix 二维树状数组
#include<iostream> #include<string> #include<string.h> #include<cstdio> usin ...
随机推荐
- Apache Spark BlinkDB
BlinkDB是一个用于在海量数据上进行交互式SQL的近似查询引擎. 它允许用户通过在查询准确性和查询响应时间之间做出权衡,完成近似查询. 其数据的精度被控制在允许的误差范围内. 为了达到这个目标,B ...
- homework 08_2 C++11新特性作业之二
---恢复内容开始--- 1.使用Lambda表达式计算“hello world!”中字母e和i的数量 下面是代码: #include "stdafx.h" #include< ...
- Linux下文件的压缩与打包
一.Linux下常见的文件压缩命令: 在Linux的环境中,压缩文件的扩展名大多是:『*.tar, *.tar.gz, *.tgz, *.gz, *.Z, *.bz2』,为什么会有这样的扩展名呢? 这 ...
- Gym 100507C Zhenya moves from parents (线段树)
Zhenya moves from parents 题目链接: http://acm.hust.edu.cn/vjudge/contest/126546#problem/C Description Z ...
- [iOS微博项目 - 2.1] - 获得新浪授权接口
A.如何获得新浪的授权接口 登陆新浪的开放平台 注册新浪账号 创建应用 获得应用id和请求地址 查阅相关API 关联需要进行测试的账号 1.登陆开放平台 http://open.weibo.com ...
- 在C#调用C++的DLL简析(一)——生成非托管dll
经过一晚上的折腾,还是下点决心将些许的心得写下来,以免以后重复劳动. C#与C/C++相 比,前者的优势在于UI,后者的优势在于算法,C++下的指针虽然恶心,若使用得当还是相当方便的,最重要的问题是, ...
- ActiveMQ JMS 在发邮件中的使用
ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久 ...
- Win7激活后添加grub引导Linux最简单方法
因为Win7(Vista同理)的激活方式是通过grub摸你OEM的Slic信息,所以主引导分区MBR被这个grub占用,以此才能激活WIn7.但是如果想同时安装Linux在别的分区,就会产生问题:gr ...
- Oracle DataGuard搭建(二)
三.配置备库 创建catalog数据库 用dbca创建数据库,用oracle自带模板,不用em,启用归档,同一管理密码oracle,global name:dbcat1.node249.gewara, ...
- Ribbon 窗体的 MDI 子窗体使用 TabbedMDIManager 切换时工具条闪屏问题的解决办法
补充说明: 此问题已经在新版本中解决(15.2.6),方法更加简单,只需要在 MDIChild 窗体的 Create 方法中,将 Ribbon 的 Visible 属性设置为 false 就可以了,且 ...