poj 2155 B - Matrix 二维树状数组
#include<iostream>
#include<string>
#include<string.h>
#include<cstdio>
using namespace std;
const int maxn=;
int n;
int c[maxn][maxn];
int lowbit(int x) { return x&(-x); }
void update(int x,int y)
{
for(int i = x; i; i -= lowbit(i))
for(int j = y; j; j -= lowbit(j))
++c[i][j];
}
int query(int x, int y)
{
int sum = ;
for(int i = x; i <= n; i += lowbit(i))
for(int j = y; j <= n; j+= lowbit(j))
sum += c[i][j];
return sum;
}
int main()
{
int T; cin>>T;
while(T--)
{
memset(c,,sizeof(c));
int x; cin>>n>>x;
while(x--)
{
char s; cin>>s;
int a,b,c,d;
if(s == 'C')
{
cin>>a>>b>>c>>d;
update(c, b-);
update(a-, d);
update(a-, b-);
update(c, d);
}
else{cin>>a>>b; cout<<(query(a, b) & ? "" : "")<<endl; }
}
puts("");
}
}
poj 2155 B - Matrix 二维树状数组的更多相关文章
- POJ 2155:Matrix 二维树状数组
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 21757 Accepted: 8141 Descripti ...
- POJ 2155 Matrix(二维树状数组,绝对具体)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 20599 Accepted: 7673 Descripti ...
- [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 (二维树状数组)
题意:给你一个矩阵开始全是0,然后给你两种指令,第一种:C x1,y1,x2,y2 就是将左上角为x1,y1,右下角为x2,y2,的这个矩阵内的数字全部翻转,0变1,1变0 第二种:Q x1 y1,输 ...
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- 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 二维树状数组的第二类应用
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17976 Accepted: 6737 Descripti ...
随机推荐
- 逆袭之旅DAY20.xia.师父指导.数据类型
2018-07-16 09:35:57 基础是王道 从码农--软件工程师--软件架构师 String 首字母大写,特殊引用类型,常量类 二.数组 存钱罐(只能放钱) 数据兼容 数组的长度(定义后长度 ...
- Java中的标签
@SuppressWarnings 简介:java.lang.SuppressWarnings是J2SE 5.0中标准的Annotation之一.可以标注在类.字段.方法.参数.构造方法,以及局部变量 ...
- 8188EU 在AM335X MC183上以AP+STA工作
[目的] 8188EU 在AM335X MC183上以AP+STA工作. [环境] 1. Ubuntu 16.04发行版 2. linux-3.2.0-psp04.06.00.11 3. MC1 ...
- tomcat vue webpack vue-router 404
社区已经有结局方案了, http://blog.csdn.net/hayre/article/details/70145513
- Linux系统从零到高手的进阶心得
初次了解到Linux系统还是在我初中的时候,那时候正是在一个中二年龄,喜欢看小说,对于小说中出现的明显的非现实场景感到十分钦佩.羡慕,并常常幻想自己也有小说主人公那样的本领.那正是在这样一个充满幻想的 ...
- SqlServer2008备份与还原(完整图示版)
一.备份 1.在需要备份的数据库上,右键——任务——备份,如下: 2.选择备份到哪个路径和备份名字: 点击“添加”,如下, 3.上面点击“确定”后,回到第一个页面,选中刚才添加的路径和文件名 4.左上 ...
- 5.5 C++重载赋值操作符
参考:http://www.weixueyuan.net/view/6383.html 总结: 重载赋值操作符同重载类的是拷贝构造函数的原因是一样,将一个对象拷贝给另一个对象,同时当类中存在指针类型的 ...
- html页面技巧
Query获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为S ...
- centos7安装mysql mariadb
从最新版本的linux系统开始,默认的是 Mariadb而不是mysql! 使用系统自带的repos安装很简单: yum install -y mariadb mariadb-server 启动mar ...
- 牛客多校第四场 G Maximum Mode
链接:https://www.nowcoder.com/acm/contest/142/G来源:牛客网 The mode of an integer sequence is the value tha ...