/*
树状数组第三种模板(改段求段)不解释!
不明白的点这里: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(树状数组第三种模板改段求段)的更多相关文章

  1. A Simple Problem with Integers(树状数组HDU4267)

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...

  2. HDU 4267 A Simple Problem with Integers --树状数组

    题意:给一个序列,操作1:给区间[a,b]中(i-a)%k==0的位置 i 的值都加上val  操作2:查询 i 位置的值 解法:树状数组记录更新值. 由 (i-a)%k == 0 得知 i%k == ...

  3. POJ3468 A Simple Problem With Integers 树状数组 区间更新区间询问

    今天学了很多关于树状数组的技巧.一个是利用树状数组可以简单的实现段更新,点询问(二维的段更新点询问也可以),每次修改只需要修改2个角或者4个角就可以了,另外一个技巧就是这题,原本用线段树做,现在可以用 ...

  4. POJ3468 A Simple Problem with Interger [树状数组,差分]

    题目传送门 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 1 ...

  5. A Simple Problem with Integers_树状数组

    Problem Description Let A1, A2, ... , AN be N elements. You need to deal with two kinds of operation ...

  6. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  7. poj 3468 A Simple Problem with Integers 【线段树-成段更新】

    题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...

  8. 线段树(成段更新) POJ 3468 A Simple Problem with Integers

    题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...

  9. hdu 2642二维树状数组 单点更新区间查询 模板题

    二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...

随机推荐

  1. javaweb学习总结(二十五)——jsp简单标签开发(一)

    一.简单标签(SimpleTag) 由于传统标签使用三个标签接口来完成不同的功能,显得过于繁琐,不利于标签技术的推广, SUN公司为降低标签技术的学习难度,在JSP 2.0中定义了一个更为简单.便于编 ...

  2. React+BootStrap+ASP.NET MVC实现自适应和组件的复用

    系统展示如下 1.前端采用bootstrap3进行架构 2.后端采用asp.net mvc进行开发 开发工具vs2010 mvc4需要安装sp1的补丁. 3.js组件的封装采用react 1.新建mv ...

  3. windows xp/7命令提示符强制结束指定进程

    开始----“运行 ”输入cmd ,然后在命令提示符下输入tasklist,出现如下列表: Image Name                     PID Session Name        ...

  4. 转:SDL2源代码分析

    1:初始化(SDL_Init()) SDL简介 有关SDL的简介在<最简单的视音频播放示例7:SDL2播放RGB/YUV>以及<最简单的视音频播放示例9:SDL2播放PCM>中 ...

  5. Correct use of System.Web.HttpResponse.Redirect

    from:https://blogs.msdn.microsoft.com/tmarq/2009/06/25/correct-use-of-system-web-httpresponse-redire ...

  6. GTD时间管理(2)---管理收集箱

    通过上面一篇文章,相信大家对GTD收集有了原理大致的了解,如果大家对收集不是很了解,可以去看一下. 当我们收集到很多想法和事情之后,在晚会的时候必须要清空收集箱,否则收集箱会堆积如山,最终收集箱成了垃 ...

  7. old header

    海纳百川 山不拒土 No Backspace in Real Life. Love Life![Cloud][LBS][GIS][GPS][MAPS][C++][Java]

  8. LeetCode:Roman to Integer,Integer to Roman

    首先简单介绍一下罗马数字,一下摘自维基百科 罗马数字共有7个,即I(1).V(5).X(10).L(50).C(100).D(500)和M(1000).按照下述的规则可以表示任意正整数.需要注意的是罗 ...

  9. First MarkDown Blog

    #First MarkDown Blog ##Title1 ##Tiltle2

  10. iSAC测试报告

    iSAC测试报告 测试码流:24k bit/s 测试环境:三星i9250  CPU 1.2G*2   ram:1G  TI芯片  OMAP 4460 双核1.2GHz MOTO ME722  CPU ...