#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<set>
#include<map>
#include<vector>
#include<cstring>
#include<stack>
#include<cmath>
#include<queue>
//#include <bits/stdc++.h>
using namespace std;
#define LL long long
const int maxn=;
struct node
{
LL sum,val;
}tree[maxn*]; void pushup(int rt)
{
tree[rt].sum=tree[rt<<].sum+tree[rt<<|].sum;
}
void pushdown(int rt,int m)
{
if(tree[rt].val)
{
tree[rt<<].val+=tree[rt].val;
tree[rt<<|].val+=tree[rt].val;
tree[rt<<].sum+=(LL)(m-(m>>))*tree[rt].val;
tree[rt<<|].sum+=(LL)(m>>)*tree[rt].val;
tree[rt].val=;
}
} void build_tree(int l,int r,int rt)
{
tree[rt].val=;
if(l==r)
{
scanf("%I64d",&tree[rt].sum);
return ;
}
int m=(l+r)>>;
build_tree(l,m,rt<<);
build_tree(m+,r,rt<<|);
pushup(rt);
} LL query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
return tree[rt].sum;
}
int m=(l+r)>>;
pushdown(rt,r-l+);
LL ans=;
if(L<=m)
ans+=query(L,R,l,m,rt<<);
if(m<R)
ans+=query(L,R,m+,r,rt<<|);
pushup(rt);
return ans;
} void update(int L,int R,int add,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
tree[rt].sum+=(LL)add*(r-l+);
tree[rt].val+=add;
return;
}
pushdown(rt,r-l+);
int m=(l+r)>>;
if(L<=m)
update(L,R,add,l,m,rt<<);
if(R>m)
update(L,R,add,m+,r,rt<<|);
pushup(rt);
} int main()
{
int n,a,b,q;
LL c;
while(~scanf("%d%d",&n,&q))
{
build_tree(,n,);
char s[];
while(q--)
{
scanf("%s",s);
if(s[]=='Q')
{
cin>>a>>b;
cout<<query(a,b,,n,)<<endl;
}
else if(s[]=='C')
{
cin>>a>>b>>c;
update(a,b,c,,n,);
}
}
}
return ;
}

POJ 3468 A Simple Problem with Integers 线段树 区间更新的更多相关文章

  1. poj 3468 A Simple Problem with Integers (线段树区间更新求和lazy思想)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 75541   ...

  2. (简单) POJ 3468 A Simple Problem with Integers , 线段树+区间更新。

    Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...

  3. [POJ] 3468 A Simple Problem with Integers [线段树区间更新求和]

    A Simple Problem with Integers   Description You have N integers, A1, A2, ... , AN. You need to deal ...

  4. poj 3468 A Simple Problem with Integers 线段树区间更新

    id=3468">点击打开链接题目链接 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072 ...

  5. POJ 3468 A Simple Problem with Integers(线段树,区间更新,区间求和)

    A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 67511   ...

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

    题目地址:POJ 3468 打了个篮球回来果然神经有点冲动. . 无脑的狂交了8次WA..竟然是更新的时候把r-l写成了l-r... 这题就是区间更新裸题. 区间更新就是加一个lazy标记,延迟标记, ...

  7. POJ 3468 A Simple Problem with Integers(线段树区间更新,模板题,求区间和)

    #include <iostream> #include <stdio.h> #include <string.h> #define lson rt<< ...

  8. poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和

    A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...

  9. poj 3468 A Simple Problem with Integers 线段树区间加,区间查询和(模板)

    A Simple Problem with Integers Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://poj.org/problem?i ...

随机推荐

  1. laravel homestead

    laravel homestead真是个好东西啊,折腾了很长时间,终于ok啦. 安装成功之后,在-目录下有个homstead,进入执行vagrant up clzdeMBP:Homestead clz ...

  2. 我写了个教程《一步步教你把ubuntu安装到U盘》

    一步步教你把ubuntu安装到U盘 作者 Val 2452013147@qq.com 原因: 由于某些原因(学生党),需要把ubuntu安装到U盘到处走,百度了一下,教程都不是很好,要么很复杂,要么不 ...

  3. Pycharm使用技巧

    1.代码配色,即主题 pycharm自带的配色方案都很难看,网上的配色方案又很难看,所以根据其他ide的Monokai配色方案,自己定义了一个. pycharm Monokai主题下载:http:// ...

  4. SQL常用命令浅析

    表操作备注:操作之前使用“use <数据库名>”应连接某个数据库.建表命令:create table <表名> (<字段名 1> <类型 1> [,.. ...

  5. Silverlight之我见

    好长时间没搞Silverlight方面的开发了,原本都以为自己早已忘记,然而前阵子(确切一点说,是挺长时间以前了)的时候,发布Windows10的时候,微软宣布新的浏览器将重新开发,关键是后半句引起了 ...

  6. Unity3d Shader开发(三)Pass(Culling & Depth Testing)

    剔除是一种通过避免渲染背对观察者的几何体面来提高性能的优化措施.所有几何体都包含正面和反面.剔除基于大多数对象都是封闭的事实:如果你有一个立方体,你不会看到背离你的那一面(总是只有一面在你的前方),因 ...

  7. 认识基本的UI资源

    什么是UI精灵(Sprite) 在制作UI时,经常将一些零碎的小的UI资源(比如,一个小箭头,一个按钮等)打包成一张大图,然后在使用时,只使用这个大图中的一部分,那么这一块"被切出来&quo ...

  8. 【Selenium】自动化调试后C盘越来越大

    在本机调试了一段时间自动化脚本后发现C盘占用越来越大,增长速度比较明显 通过360等工具清理系统垃圾表明并不好使 最后在系统临时文件中看到大量因为调试或不正常结束而Driver而产生的临时文件 具体方 ...

  9. uva 1475 - Jungle Outpost

    半平面交,二分: 注意,题目的点是顺时针给出的: #include<cstdio> #include<algorithm> #include<cmath> #def ...

  10. ***PHP 去除换行符

    PHP在不同的系统中,换行是不同的 Linux:\n Windows:\r\n mac:\r 所以去除回车换行的方法: 1.使用php定义好的变量(比较好的方法,推荐) $str= str_repla ...