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 ...
随机推荐
- winfrom程序如何做到快速关闭窗体
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { Process.GetCurrentProcess().Ki ...
- 研华外触发实验PCI1714板卡安装事项
1.安装在工控机中 研华的旧版本驱动和新版本的驱动文件不能同时安装,有冲突. 如何安装新版本: 卸载旧版本.控制面板中的device manager. 安装新版本的DAQ NAVI SDK文件,安装P ...
- Android虚拟机Classic qemu does not support SMP问题记录
不及之前重装了一次系统,导致要重新搭建android开发环境,但是在启动AVD时queue遇到了这个问题 androidstudio中看到的是这个样子 大概查了一下,应该是创建虚拟机是选择的cpu构架 ...
- [iOS 基于CoreBluetooth的蓝牙4.0通讯]
一.首先大致介绍下蓝牙4.0的模式,中心和周边: 一般情况下,iPhone作为中心,接收来自周边传感器(比如手环等)采集的数据. 二.那整一个数据通讯的协议是怎样的呢? 为什么要一层层搞这么复杂呢?据 ...
- Beta Daily Scrum 第六天
[目录] 1.任务进度 2.困难及解决 3.燃尽图 4.代码check-in 5.总结 1. 任务进度 学号 今日完成 明日完成 612 昨天完成任务,今天看有没有bug,找一找 好像没什么事 615 ...
- Android学习笔记——ListView
该工程的功能是实现在一个activity中显示一个列表 以下代码是MainActivity.java中的代码 package com.example.listview; import java.uti ...
- Nginx+PHP-fpm高负载优化及压力测试方法
Nginx+PHP-fpm组合,以内存占用小,负载能力强壮的特点,成为小内存VPS建站的首选组合.我们一起来探讨一下nginx+php-fpm高负载的优化方法. 先来看看nginx配置参数的优化.ng ...
- javascript字符串截取的substring、substr和slice
本文详细的介绍了javascript中substring().substr()和slice()三个JS字符串截取的方法,substring()方法用于提取字符串中介于两个指定下标之间的字符.subst ...
- JS获取checkbox的个数
本文算是转载自网络,当时用了他的函数,现在想总结一下,但忘了原文地址了 ================================================================ ...
- Yii2 如何更好的在页面注入JavaScript
先添加一个widgets <?php /** * User: yiqing * Date: 14-9-15 * Time: 下午12:09 */ namespace common\widgets ...