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 ...
随机推荐
- linux中firewall与iptables防火墙服务
火墙firewall-cmd --state 查看火墙的状态firewall-cmd --get-active-zones 目前所处的域firewall-cmd --get-default-zone ...
- shell 获取hive表结构
hive -S -e "select * from db_name.table_name limit 0"|grep table_name|xargs -n1|sed 's/tab ...
- 创建第一个vue工程
vue创建项目(npm安装→初始化项目) 第一步npm安装 首先:先从nodejs.org中下载nodejs 图1 双击安装,在安装界面一直Next 图2 图3 图4 直到Finish ...
- PHP、thinkPHP5.0开发网站文件管理功能(三)重命名文件
public function renames(){ if(request()->isAjax()){ $file = iconv('UTF-8','GB2312',urldecode(inpu ...
- JavaSE---Collections
1.简介: Collections是一个工具类 1.1 排序 a,正序 sort是其静态方法,有2种参数形式: public static <T extends Comparable<? ...
- goodBye wordPress
2016-07-28,我自己在GoDaddy上面注册了一个自己的域名,www.codetree.tech,同时在老薛主机上面购买了一个主机域名.我搭建了一个属于自己的博客,开心了很久.最近收到了域名续 ...
- 牛客网Java刷题知识点之父类中的私有内容,子类是否具备? 子类不可直接,但可间接访问父类中的私有内容?
不多说,直接上干货! 父类中的私有内容,子类是否具备? 答:不具备 子类不可直接,但可间接访问父类中的私有内容 这样情况,开发中不所见,但是,面试的时候,必考非常常见.
- springmvc+mybatis+sql server实现简单登录功能
一.源码: 1.Users.java package com.login.entity; import java.io.Serializable; public class Users impleme ...
- php-fpm 进程在云服务器cpu分配不均匀
8核的云服务器,开了200个php-fpm进程,用top命令查看 大部分进程都在cpu 0 上跑着,导致其他cpu 负载很低,cpu分配不均匀: 使用shell 解决问题: 列出所有php-fpm ...
- Java的ThreadContext类加载器
疑惑 以前在看源码的时候,总是会遇到框架里的代码使用Thread.currentThread.getContextClassLoader()获取当前线程的Context类加载器,通过这个Context ...