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& ...
随机推荐
- Atom插件安装及常用插件推荐
Atom是个不错的文本编辑工具,也该可以改造成IDE用,主要靠插件实现各种扩展功能. 因为网络环境的原因,在线安装不容易成功,一般选择手动安装. 以下是我搜索网络资源后总结的手动安装方法. Atom插 ...
- 如何处理Win7连接vpn时报错789的问题
[转]VPN错误提示: vpn连接出错789:L2TP连接尝试失败,因为安全层在初始化与远程计算机的协商时遇 (2014-08-11 15:09:10)转载▼标签: it xp连接VPN错误提示: v ...
- How do I check if a type is a subtype OR the type of an object?
To check if a type is a subclass of another type in C#, it's easy: typeof (SubClass).IsSubclassOf(ty ...
- 【CUDA学习】GPU硬件结构
GPU的硬件结构,也不是具体的硬件结构,就是与CUDA相关的几个概念:thread,block,grid,warp,sp,sm. sp: 最基本的处理单元,streaming processor 最 ...
- 【转】我应该直接学Swift还是Objective-C?
(本文作者Amit Bijlani,由CocoaChina翻译) 当我们发布了Swift语言学习课程之后,收到了很多邮件和私信来问自己是否还需要学习C或者Objective-C.此外,人们似乎还在迷惑 ...
- GTD时间管理(2)---管理收集箱
通过上面一篇文章,相信大家对GTD收集有了原理大致的了解,如果大家对收集不是很了解,可以去看一下. 当我们收集到很多想法和事情之后,在晚会的时候必须要清空收集箱,否则收集箱会堆积如山,最终收集箱成了垃 ...
- mycat服务启动{管理模块启动过程}
mycat启动的时候启动了三个模块 1:NIOConnector(负责链接mysql数据库,连接池以数据库为准不以链接字符串为准), 1:NIOAcceptor,ManagerConnectionFa ...
- [Android] 转移“植物大战僵尸2”存档的办法,无需root
作者:zyl910 查过了很多文章,都说需要root后才能转移存档.但很多时候是不能root的,此时该怎么办呢? 我研究了很久,最终找到了一种办法,无需root也能转移存档. 一.备份 我用的是联想手 ...
- error while loading shared libraries: /usr/lib64/libc.so.6: invalid ELF header
在安装一个程序的时候提示libc.so.6过旧,但是查看libc.so的版本是最新的,于是尝试使用尝试软链接 ln -s /usr/lib64/libc.so /usr/lib64/libc.so. ...
- Maven Learning - Direct Dependencies & Transitive Dependencies
Dependencies declared in your project's pom.xml file often have their own dependencies. The main dep ...