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 ...
随机推荐
- ADO执行事务
在工作中遇到,需要批量提交的.在sql2008以后有表变量定义,可以实现.但个人比较习惯用C#,就有下面代码,直接上代码... using (SqlConnection conn = new SqlC ...
- js中url有中文的转码方法
转载:https://www.cnblogs.com/chiangfai/p/6073000.html
- 19. Remove Nth Node From End of List(C++,Python)
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- toTop插件(三)
前言 当窗体内容过多会出现滚动, 点击回到顶部滚动条在在上边(大家都懂得,我语文学的不好,表达不清^_^) 看代码 CSS : .toTop{ position: fixed; width: 50px ...
- hdfs namenode/datanode工作机制
一. namenode工作机制 1. 客户端上传文件时,namenode先检查有没有同名的文件,如果有,则直接返回错误信息.如果没有,则根据要上传文件的大小以及block的大小,算出需要分成几个blo ...
- silverlight vs2010 需要缺少的web组件才能加载
在打开一个开源的Silverlight项目是遇到如图所示的问题,点击是后没有反应. 查了资料,需要安装微软的webpi(Microsoft Web Platform Installer) webpi的 ...
- TCP和UDP的区别以及各自应用
TCP(Transmission Control Protocol,传输控制协议)和UDP(User Datagram Protocol,用户数据报协议)是运输层的两个主要协议,均是互联网的正式标准. ...
- 性能测试工具LoadRunner05-LR之Virtual User Generator html模式与url模式
“HTML-based script”说明 在默认情况下,选择“HTML-based script”,说明脚本中采用HTML页面的形式来表示,这种方式的脚本容易维护,容易理解,推荐这种方式录制 “UR ...
- PHP文件访问
文件和目录处理函数 basename — 返回路径中的文件名部分 | Returns trailing name component of path | chgrp — 改变文件所属的组 | Chan ...
- 读取和写入Cookies
#region 读取或写入cookie 2 /// <summary> 3 /// 写cookie值 4 /// </summary> 5 /// <param name ...