poj 3486 A Simple Problem with Integers(树状数组第三种模板改段求段)
/*
树状数组第三种模板(改段求段)不解释!
不明白的点这里:here!
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 100005
using namespace std; typedef long long LL; LL ss[N], B[N], C[N]; int n, m; void addB(int x, int k){//B[i]表示被1...i整体一共加了多少的总和
for(int i=x; i<=n; i+=i&(-i)) B[i]+=x*k;
} void addC(int x, int k){//1....x节点的每个节点的增量
for(int i=x; i>; i-=i&(-i)) C[i]+=k;
} LL sumB(int x){
LL s=;
for(int i=x; i>; i-=i&(-i)) s+=B[i];
return s;
} LL sumC(int x){//x节点总共的增量
LL s=;
for(int i=x; i<=n; i+=i&(-i)) s+=C[i];
return s;
} LL sum(int x){
return x== ? : sumC(x)*x + sumB(x-);
} void update(int a, int b, int c){
addB(b, c);
addC(b, c);
if(a->){
addB(a-, -c);
addC(a-, -c);
}
} int main(){
int m;
while(scanf("%d%d", &n, &m)!=EOF){
for(int i=; i<=n; ++i){
scanf("%lld", &ss[i]);
ss[i]+=ss[i-];
}
char ch[];
int a, b, c;
while(m--){
scanf("%s", ch);
if(ch[]=='Q'){
scanf("%d%d", &a, &b);
printf("%lld\n", ss[b]-ss[a-]+sum(b)-sum(a-));
}
else{
scanf("%d%d%d", &a, &b, &c);
update(a, b, c);
}
}
}
return ;
}
poj 3486 A Simple Problem with Integers(树状数组第三种模板改段求段)的更多相关文章
- A Simple Problem with Integers(树状数组HDU4267)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- HDU 4267 A Simple Problem with Integers --树状数组
题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val 操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...
- POJ3468 A Simple Problem With Integers 树状数组 区间更新区间询问
今天学了很多关于树状数组的技巧.一个是利用树状数组可以简单的实现段更新,点询问(二维的段更新点询问也可以),每次修改只需要修改2个角或者4个角就可以了,另外一个技巧就是这题,原本用线段树做,现在可以用 ...
- POJ3468 A Simple Problem with Interger [树状数组,差分]
题目传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 1 ...
- A Simple Problem with Integers_树状数组
Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of operation ...
- POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)
POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...
- poj 3468 A Simple Problem with Integers 【线段树-成段更新】
题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...
- 线段树(成段更新) POJ 3468 A Simple Problem with Integers
题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...
- hdu 2642二维树状数组 单点更新区间查询 模板题
二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...
随机推荐
- bzoj 1637: [Usaco2007 Mar]Balanced Lineup
1637: [Usaco2007 Mar]Balanced Lineup Time Limit: 5 Sec Memory Limit: 64 MB Description Farmer John ...
- Linux Buffers和Cached的区别(转)
在linux下使用free命令查看内存使用情况,有buffers和cached两项,以下是它们的区别: buffers是为块设备设计的缓冲.比如磁盘读写,把分散的写操作集中进行,减少磁盘I/O,从而提 ...
- LPC18xx LPC43xx LPC4370 Bootrom USB DFU FPB - Flash Patch and Breakpoint Unit
What is the difference between a Bootrom vs bootloader on ARM systems Bootrom Bootrom (or Boot ROM) ...
- [转]揭秘webdriver实现原理
转自:http://www.cnblogs.com/timsheng/archive/2012/06/12/2546957.html 通过研究selenium-webdriver的源码,笔者发现其实w ...
- Apache shiro
Shiro 是一个 Apache Incubator 项目,旨在简化身份验证和授权. 学习博客:http://jinnianshilongnian.iteye.com/blog/2018398
- Lua截取utf-8编码的中英文混合字符串
参考博客:UTF8字符串在lua的截取和字数统计[转载] 需求 按字面个数来截取子字符串 函数(字符串, 开始位置, 截取长度) utf8sub(,) = 好1世界哈 utf8sub(,) = 你好1 ...
- fast db 学习
见 http://code.google.com/p/mmdbsolution/source/browse/trunk/+mmdbsolution+--username+SiliangDu1987%4 ...
- MySQL中导入 导出CSV
来自:http://blog.csdn.net/sara_yhl/article/details/6850107 导出 select * from test_info into outfile '/t ...
- WorkbookDesigner mvc里面返回file
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- win10上安装Docker
方法1:具体我没有试过,不知道win10下可以么.http://blog.csdn.net/zistxym/article/details/42918339 方法2: 先安装VirtualBox(下载 ...