poj1195Mobile phones(二维树状数组)
http://poj.org/problem?id=1195
模版题 i写成k了 找了一个多小时没找出来。。
#include <iostream>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<cstdio>
using namespace std;
#define N 1050
#define lowbit(x) (x&(-x))
int n,c[N][N];
void add(int i,int j,int da)
{
int k;
while(i<=n)
{
k = j;
while(k<=n)
{
c[i][k]+=da;
k+=lowbit(k);
}
i+=lowbit(i);
}
}
int getsum(int i,int j)
{
int sum=,k;
while(i)
{
k = j;
while(k)
{
sum+=c[i][k];
k-=lowbit(k);
}
i-=lowbit(i);
}
return sum;
}
int main()
{
int k,a,b,cc,d,t;
cin>>t>>n;
memset(c,,sizeof(c));
while(scanf("%d",&k),k!=)
{
if(k==)
{
scanf("%d%d%d",&a,&b,&cc);
add(a+,b+,cc);
}
else if(k==)
{
scanf("%d%d%d%d",&a,&b,&cc,&d);
a++;b++;cc++;d++;
printf("%d\n",getsum(cc,d)-getsum(a-,d)-getsum(cc,b-)+getsum(a-,b-));
}
}
return ;
}
poj1195Mobile phones(二维树状数组)的更多相关文章
- POJ 1195:Mobile phones 二维树状数组
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 16893 Accepted: 7789 De ...
- 【poj1195】Mobile phones(二维树状数组)
题目链接:http://poj.org/problem?id=1195 [题意] 给出一个全0的矩阵,然后一些操作 0 S:初始化矩阵,维数是S*S,值全为0,这个操作只有最开始出现一次 1 X Y ...
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- poj_1195Mobile phones,二维树状数组
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> us ...
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- 【POJ1195】【二维树状数组】Mobile phones
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones【二维树状数组】
<题目链接> 题目大意: 一个由数字构成的大矩阵,开始是全0,能进行两种操作1) 对矩阵里的某个数加上一个整数(可正可负)2) 查询某个子矩阵里所有数字的和要求对每次查询,输出结果 解题分 ...
随机推荐
- ECSHOP 支付宝发货确认接口,记录支付宝返回的交易号
1,在order_info 数据表尾添加trade_no 字段 数据表尾怎么添加trade_no 字段 ECSHOP为了支付宝发货确认接口,需要记录支付宝返回的交易号 1,在order_info 数据 ...
- .net mvc 防止 xss 与 CSRF
CSRF(Cross-site request forgery跨站请求伪造,也被称成为“one click attack”或者session riding,通常缩写为CSRF或者XSRF,是一种对网站 ...
- ShowMask
<html> <head> <script type="text/javascript"> function showMask(){ var a ...
- 转 在无法通过yum下载非标准包时,怎么办
在CentOS下,我们可以通过yum来下载或更新rpm包,但是标准的源(repository)里只提供一部分的rpm包,虽然大部分情况下,这些包是够用的.但是有时候还是需要下载其他的一些非标准的包,如 ...
- javascript insertBefore 和 appendChild
js的appendChild()方法 :在一个元素内部追加一个子节点. js的insertBefore()方法:在一个元素内部指定的子节点之前插入子节点. 很明显,appendChild()方法只需要 ...
- 1030. Travel Plan (30)
时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A traveler's map gives the dista ...
- 计算器(delphi)
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- AJAX 基础知识
1.AJAX 是一种用于创建快速动态网页的技术.而是一种用于创建更好更快以及交互性更强的 Web 应用程序的技术.通过在后台与服务器进行少量数据交换,AJAX 可以使网页实现异步更新.这意味着可以在不 ...
- OOP三类继承的区别
OOP继承的区别提纲: 1. 普通类继承,并非一定要重写父类方法.2. 抽象类继承,如果子类也是一个抽象类,并不要求一定重写父类方法.如果子类不是抽象类,则要求子类一定要实现父类中的抽象方法.3. 接 ...
- mac使用wget下载网站(仿站)
wget -c -r -np -k -L -p http://www.xxxx.com 参考 wget的安装 http://blog.csdn.net/ssihc0/article/details/7 ...