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& ...
随机推荐
- Head First Design Patterns
From Head First Design Patterns. Design Principle: Idnetify the aspects of your application that var ...
- OpenGL学习进程(11)第八课:颜色绘制的详解
本节是OpenGL学习的第八个课时,下面将详细介绍OpenGL的颜色模式,颜色混合以及抗锯齿. (1)颜色模式: OpenGL支持两种颜色模式:一种是RGBA,一种是颜色索引模式. R ...
- Category和Extension
转: http://blog.csdn.net/leikezhu1981/article/details/19091049 一.概述 类别是一种为现有的类添加新方法的方式. 利用Objective-C ...
- IOS适配
• Default.png(图片尺寸为320x480):显示在非Retina-3.5英寸屏幕上(iPhone3G\iPhone3GS,屏幕分辨率为320x480) • Default@2x.png(图 ...
- 实施vertex compression所遇到的各种问题和解决办法
关于顶点压缩,好处是可以减少带宽,一定程度提高加载速度,可以提高约5-10%的fps,特别是mobile上,简单描述就是: 压缩之前(32字节) position float3 12normal fl ...
- JS 清除字符串数组中,重复元素
<script language="JavaScript"> <!-- var arrData=new Array(); for(var i=0; i<10 ...
- Oracle的悲观锁和乐观锁---摘抄
1.无论是选择悲观锁策略,还是乐观锁策略.如果一个对象被上了锁,那么该对象都会受这个锁的控制和影响.如果这个锁是个排它锁,那么其它会话都不能修改它. 2.选择悲观锁策略,还是乐观锁策略,这主要是由应用 ...
- GitHub上整理的一些工具[转载]
Source:http://segmentfault.com/q/1010000002404545 技术站点 Hacker News:非常棒的针对编程的链接聚合网站 Programming reddi ...
- 老王教您怎么做cass7.1 8.0 9.1所有系列的复制狗 加密狗 破解狗
cass7.1 8.0 9.1所有系列的复制狗 加密狗 破解狗本来是出于好奇看到网上有这样的东西,学了下感觉挺简单的,如果你是cass的初学者想仅仅是想学习这个软件,不想花大价格购买正版的,这个是可以 ...
- Source Insight 使用
1.括号配对高亮:“在前括号左侧,后括号左侧” 双击鼠标左键,可以选定匹配括号和其中内容(<>,(),L{R},[]之间) 2.让{ 和 } 不缩进:Options -> Docum ...