C - A Simple Problem with Integers
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n,m;
struct nond{
int l,r;
long long sum,flag;
}tree[MAXN*];
void up(int now){
tree[now].sum=tree[now*].sum+tree[now*+].sum;
}
void build(int now,int l,int r){
tree[now].l=l;tree[now].r=r;
if(tree[now].l==tree[now].r){
scanf("%lld",&tree[now].sum);
return ;
}
int mid=(tree[now].l+tree[now].r)/;
build(now*,l,mid);
build(now*+,mid+,r);
up(now);
}
void down(int now){
tree[now*].flag+=tree[now].flag;
tree[now*].sum+=(tree[now*].r-tree[now*].l+)*tree[now].flag;
tree[now*+].flag+=tree[now].flag;
tree[now*+].sum+=(tree[now*+].r-tree[now*+].l+)*tree[now].flag;
tree[now].flag=;
}
void change(int now,int l,int r,int k){
if(tree[now].l==l&&tree[now].r==r){
tree[now].sum+=(tree[now].r-tree[now].l+)*k;
tree[now].flag+=k;
return ;
}
if(tree[now].flag) down(now);
int mid=(tree[now].l+tree[now].r)/;
if(r<=mid) change(now*,l,r,k);
else if(l>mid) change(now*+,l,r,k);
else{ change(now*,l,mid,k);change(now*+,mid+,r,k); }
up(now);
}
long long query(int now,int l,int r){
if(tree[now].l==l&&tree[now].r==r)
return tree[now].sum;
if(tree[now].flag) down(now);
int mid=(tree[now].l+tree[now].r)/;
if(r<=mid) return query(now*,l,r);
else if(l>mid) return query(now*+,l,r);
else return query(now*,l,mid)+query(now*+,mid+,r);
}
int main(){
scanf("%d%d",&n,&m);
build(,,n);
for(int i=;i<=m;i++){
char c;int x,y,z;
scanf("\n%c%d%d",&c,&x,&y);
if(c=='Q') cout<<query(,x,y)<<endl;
else if(c=='C'){ scanf("%d",&z);change(,x,y,z); }
}
}
C - A Simple Problem with Integers的更多相关文章
- POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)
A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...
- POJ 3468 A Simple Problem with Integers(线段树/区间更新)
题目链接: 传送门 A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Description Yo ...
- poj 3468:A Simple Problem with Integers(线段树,区间修改求和)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 58269 ...
- ACM: A Simple Problem with Integers 解题报告-线段树
A Simple Problem with Integers Time Limit:5000MS Memory Limit:131072KB 64bit IO Format:%lld & %l ...
- poj3468 A Simple Problem with Integers (线段树区间最大值)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92127 ...
- POJ3648 A Simple Problem with Integers(线段树之成段更新。入门题)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 53169 Acc ...
- BZOJ-3212 Pku3468 A Simple Problem with Integers 裸线段树区间维护查询
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1278 Sol ...
- POJ 3468 A Simple Problem with Integers(线段树区间更新区间查询)
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 92632 ...
- A Simple Problem with Integers(树状数组HDU4267)
A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- A Simple Problem with Integers
A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 77964 Acc ...
随机推荐
- Codeforces--106C--Buns(背包)
Buns Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Status ...
- B3300 [USACO2011 Feb]Best Parenthesis 模拟
这是我今天遇到最奇怪的问题,希望有人帮我解释一下... 一开始我能得90分: #include<iostream> #include<cstdio> #include<c ...
- GROUPPING和ROLLUP的基本知识
1.GROUPPING 是一个聚合函数,它产生一个附加的列,当用 CUBE 或 ROLLUP 运算符添加行时,附加的列输出值为1,当所添加的行不是由 CUBE 或 ROLLUP 产生时,附加列值为0. ...
- mybatis中if标签判断字符串相等问题
mybatis 映射文件中,if标签判断字符串sfyx变量是否是字符串Y的时候,发现并不管用: <if test="sfyx=='Y' "> and 1=1 </ ...
- Gold Balanced Lineup(hash)
http://poj.org/problem?id=3274 ***** #include <stdio.h> #include <iostream> #include < ...
- Python 31 TCP协议 、socket套接字
1.TCP协议 可靠传输,TCP数据包没有长度限制,理论上可以无限长,但是为了保证网络的效率,通常TCP数据包的长度不会超过IP数据包的长度,以确保单个TCP数据包不必再分割. (1)三次握手建链接( ...
- iOS网络——NSURLCache设置网络请求缓存
今天在看HTTP协议,看到了response头中的cache-control,于是就深入的研究了一下.发现了iOS中一个一直被我忽略的类——NSURLCache类. NSURLCache NSURLC ...
- 【SQL】BETWEEN操作符
BETWEEN 操作符在 WHERE 子句中使用,作用是选取介于两个值之间的数据范围. 操作符 BETWEEN ... AND 会选取介于两个值之间的数据范围.这些值可以是数值.文本或者日期. 注意: ...
- POJ 1000
#include <iostream> int main() { using std::cin; using std::cout; using std::endl; int a,b; ci ...
- 11.03 在外链接中用OR逻辑
select e.ename,d.deptno,d.dname,d.locfrom dept d left join emp e on(d.deptno = e.deptnoand (e.deptno ...