POJ-2155 Matrix---二维树状数组+区域更新单点查询
题目链接:
https://vjudge.net/problem/POJ-2155
题目大意:
给一个n*n的01矩阵,然后有两种操作(m次)C x1 y1 x2 y2是把这个小矩形内所有数字异或一遍,Q x y 是询问当前这个点的值是多少?n<=1000 m<=50000.
解题思路:
裸的二维树状数组,但是这里是区域更新,单点查询,
做法应该是
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<deque>
#include<sstream>
#include<cctype>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, s, t) for(int i = (s); i < (t); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e3 + ;
const double eps = 1e-;
const int INF = << ;
const int dir[][] = {,,,,,-,-,};
const double pi = 3.1415926535898;
int T, n, m, cases;
int tree[maxn][maxn];
int lowbit(int x)
{
return x&(-x);
}
int sum(int x, int y)
{
int ret = ;
for(int i = x; i <= n; i += lowbit(i))
{
for(int j = y; j <= n; j += lowbit(j))
ret += tree[i][j];
}
return ret;
}
void add(int x, int y, int d)
{
for(int i = x; i > ; i -= lowbit(i))
{
for(int j = y; j > ; j -= lowbit(j))
tree[i][j] += d;
}
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> T;
while(T--)
{
cin >> n >> m;
string c;
int x1, y1, x2, y2;
memset(tree, , sizeof(tree));
while(m--)
{
cin >> c;
if(c[] == 'C')
{
cin >> x1 >> y1 >> x2 >> y2;
add(x2, y2, );
add(x1 - , y1 - , );
add(x2, y1 - , -);
add(x1 - , y2, -);
}
else if(c[] == 'Q')
{
cin >> x1 >> x2;
cout<<(sum(x1, x2)&)<<endl;
}
}
if(T)cout<<endl;
}
return ;
}
POJ-2155 Matrix---二维树状数组+区域更新单点查询的更多相关文章
- 【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 (二维树状数组)
题意:给你一个矩阵开始全是0,然后给你两种指令,第一种:C x1,y1,x2,y2 就是将左上角为x1,y1,右下角为x2,y2,的这个矩阵内的数字全部翻转,0变1,1变0 第二种:Q x1 y1,输 ...
- hdu-3584 Cube---三维树状数组+区域更新单点查询
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3584 题目大意: 给定一个N*N*N多维数据集A,其元素是0或是1.A[i,j,k]表示集合中第 i ...
- POJ 2155 Matrix(二维树状数组+区间更新单点求和)
题意:给你一个n*n的全0矩阵,每次有两个操作: C x1 y1 x2 y2:将(x1,y1)到(x2,y2)的矩阵全部值求反 Q x y:求出(x,y)位置的值 树状数组标准是求单点更新区间求和,但 ...
- POJ2155 Matrix(二维树状数组||区间修改单点查询)
Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row an ...
- 牛客网 暑期ACM多校训练营(第二场)J.farm-STL(vector)+二维树状数组区间更新、单点查询 or 大暴力?
开心.jpg J.farm 先解释一下题意,题意就是一个n*m的矩形区域,每个点代表一个植物,然后不同的植物对应不同的适合的肥料k,如果植物被撒上不适合的肥料就会死掉.然后题目将每个点适合的肥料种类( ...
- POJ 2155:Matrix 二维树状数组
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 21757 Accepted: 8141 Descripti ...
- [poj2155]Matrix(二维树状数组)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 25004 Accepted: 9261 Descripti ...
随机推荐
- arraylist和linkedlist内部的实现大致是怎样的
1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机访问get和set,ArrayList优于LinkedList,因为ArrayList可以随 ...
- TXT文件导入到ORACLE数据库中
--创建表 (sqlplus执行) drop table cjw; ),phone ),city ),born ),adressJob ),mail )); ### txt导入到oracle cat ...
- 配置sudo访问
具体操作步骤 1.首先我们建立一个账户,设置密码 [root@VM_0_13_centos home]# useradd 123 [root@VM_0_13_centos home]# passwd ...
- DRF接入Oauth2.0认证[微博登录]报错21322重定向地址不匹配
DRF接入Oauth2.0认证[微博登录]报错21322重定向地址不匹配 主题自带了微博登陆接口,很简单的去新浪微博开放平台创建了网页应用,然后把APP ID和 AppSecret填好后,以为大功告成 ...
- jquery 写ajax
function down(t){ $.ajax({ url : 'selectWordDate', data : { date_time : t }, dataType : 'json' ...
- CentOS 7 Linux 卸载/安装 Mariadb MySQL mysql 5.7
[root@localhost mysql]# ls mysql-community-client--.el7.x86_64.rpm mysql-community-embedded-compat-- ...
- WPF 正確理解ContentPresenter
我們先由下圖來看類層次,可知ContentControl繼承Control,ContentPresenter繼承FrameworkElement(Control也繼承FrameworkElement) ...
- 判断表单中是否含有disabled属性
我想判断input里面是否有disabled.或者选中未选中的selected checked 属性时,需要用 prop() 方法,返回的结果是 true 或 false . attr()这个方 ...
- linux程序分析工具介绍(一)—-”/proc”
写在最前面:在开始本文之前,笔者认为先有必要介绍一下linux下的man,如果读者手头用linux系统,直接在终端输入man man便可以看到详细的说明,我在这里简单的总结一下,man命令是用来查看l ...
- 斗鱼连接弹幕Demo_pythonC#
简明扼要的说下, 就两个线程,一个 负责收数据,一个负责发心跳包. 步骤如下, 进程1,调用 发包函数,发送连接请求,然后再发送 获取弹幕类型请求,就一直循环接收数据. 进程2,循环函数,每隔45秒向 ...