POJ 1195- Mobile phones(二维BIT)
题意:
矩阵上的单点更新,范围求和
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 1100
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int bit[N][N],n,m,a[N][N];
int lowbit(int x){
return x&(-x);
}
void add(int x,int y,int d){
for(int i=x;i<=n;i+=lowbit(i))
for(int j=y;j<=n;j+=lowbit(j))
bit[i][j]+=d;
}
int sum(int x,int y){
int num=;
for(int i=x;i>;i-=lowbit(i))
for(int j=y;j>;j-=lowbit(j))
num+=bit[i][j];
return num;
}
int main()
{
int op,x1,x2,y1,y2,d;
while(~scanf("%d",&op)){
if(op==)break;
else if(op==){
scanf("%d",&n);
memset(bit,,sizeof(bit));
memset(a,,sizeof(a));
}
else if(op==){
scanf("%d%d%d",&x1,&y1,&d);
x1++;
y1++;
if(a[x1][y1]+d<)
d=-a[x1][y1];
add(x1,y1,d);
a[x1][y1]+=d;
}
else{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int tmp=sum(x2+,y2+)-sum(x2+,y1)-sum(x1,y2+)+sum(x1,y1);
printf("%d\n",tmp);
}
}
return ;
}
POJ 1195- Mobile phones(二维BIT)的更多相关文章
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- poj 1195:Mobile phones(二维线段树,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14391 Accepted: 6685 De ...
- ●POJ 1195 Mobile phones
题链: http://poj.org/problem?id=1195 题解: 二维树状数组 #include<cstdio> #include<cstring> #includ ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones(二维树状数组)
Mobile phones Time Limit: 5000MS Mem ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- 题解报告:poj 1195 Mobile phones(二维BIT裸题)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
- POJ 1195 Mobile phones【二维树状数组】
<题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...
随机推荐
- 【POJ3243】拓展BSGS(附hash版)
上一篇博文中说道了baby step giant step的方法(简称BSGS),不过对于XY mod Z = K ,若x和z并不互质,则不能直接套用BSGS的方法了. 为什么?因为这时候不存在逆元了 ...
- fhq_treap 总结
今天跟着zcg大神学了一发fhq_treap 发现在维护区间问题上fhq_treap不仅思维量小,而且代码量更小 是Splay的不错的替代品,不过至今还是有一些问题不能很好的解决 譬如查询某个数在序列 ...
- hdu 4474 Yet Another Multiple Problem
题意: 找到一个n的倍数,这个数不能含有m个后续数字中的任何一个 题解: #include<stdio.h> #include<string.h> #include<qu ...
- map的详细用法
map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力,由于这个特性,它完成有可能在我们处理一对一数据的时 ...
- [Unity菜鸟] 摄像头
1. 连接外置摄像头 2. Unity3D中调用外接摄像头,并保存为图片文件
- 使用Retrofit时出现 java.lang.IllegalArgumentException: URL query string "t={type}&p={page}&size={count}" must not have replace block. For dynamic query parameters use @Query.异常原因
/** * Created by leo on 16/4/30. */ public interface GanchaiService { @GET("digest?t={type}& ...
- linux 开机自启动软件(包含xampp方法)
linux设置apache和mysql: linux开启启动的程序一般放在/etc/rc.d/init.d/里面,/etc/init.d/是其软连接. mysql设为linux服务 cp /usr/l ...
- C# 静态类 + c# 访问器 用途
C# 静态类 http://blog.csdn.net/dodream/article/details/4588498 静态类的主要特性:仅包含静态成员. 无法实例化. 是密封的. 不能包含实例 ...
- NDK(12)Jni常用函数
参考官方文档 http://docs.oracle.com/javase/7/docs/technotes/guides/jni/ http://docs.oracle.com/javase/7/do ...
- C++ STL之排序算法
排序算法和查找算法差不多,也涉及到迭代器区间问题,关于该问题的注意事项就不在啰嗦了 一.全部排序sort.stable_sort sort是一种不稳定排序,使用时需要包含头文件algorithm 默认 ...