#include<iostream>
#include<stdio.h>
#include<string.h>
#define NN 2500000 using namespace std; typedef long long LL;
struct node
{
LL l,r,sum,flag;
} N[NN]; void build(LL l,LL r,LL i)
{
LL mid=(l+r)>>1;
N[i].flag=0;
N[i].l=l;
N[i].r=r;
N[i].sum=0;
if(l==r)
{
scanf("%lld",&N[i].sum);
return ;
}
build(l,mid,i*2);
build(mid+1,r,i*2+1);
N[i].sum=N[i*2].sum+N[i*2+1].sum;
} void renew(LL i,LL l,LL r,LL k)
{
LL mid=(N[i].l+N[i].r)>>1;
if(N[i].l==l&&N[i].r==r)
{
N[i].flag+=k;
return ;
}
N[i].sum+=(r-l+1)*k;
if(mid<l) renew(i*2+1,l,r,k);
else if(mid>=r)renew(i*2,l,r,k);
else
{
renew(i*2,l,mid,k);
renew(i*2+1,mid+1,r,k);
}
} LL query(LL i,LL l,LL r)
{
LL mid=(N[i].l+N[i].r)>>1;
if(l==N[i].l&&r==N[i].r)
{
return N[i].sum+(r-l+1)*N[i].flag;
}
if(N[i].flag)
{
N[i*2].flag+=N[i].flag;
N[i*2+1].flag+=N[i].flag;
N[i].sum+=(N[i].r-N[i].l+1)*N[i].flag;
N[i].flag=0;
}
if(l>mid) return query(i*2+1,l,r);
else if(r<=mid) return query(i*2,l,r);
else
{
return query(i*2+1,mid+1,r)+query(i*2,l,mid);
}
} int main()
{
LL n,m,suzi,a,b,i;
char s[5];
while(scanf("%lld %lld",&n,&m)!=EOF)
{
build(1,n,1);
// prLLf("sdd=%lld\n",N[8].sum);
// return 0;
for(i=1; i<=m; i++)
{
scanf("%s",s);
// return 0;
if(s[0]=='C')
{
LL a,b,c;
scanf("%lld %lld %lld",&a,&b,&c);
renew(1,a,b,c);
}
else
{
LL a,b;
scanf("%lld %lld",&a,&b);
printf("%lld\n",query(1,a,b));
}
}
}
return 0;
}

poj 3468 A Simple Problem with Integers(线段树 插线问线)的更多相关文章

  1. 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 ...

  2. 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 ...

  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 w ...

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

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

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

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

  6. POJ 3468 A Simple Problem with Integers(线段树 成段增减+区间求和)

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  7. POJ 3468 A Simple Problem with Integers //线段树的成段更新

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

  8. poj 3468 A Simple Problem with Integers 线段树加延迟标记

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

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

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

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

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

随机推荐

  1. Python爬虫--beautifulsoup 4 用法

    Beautiful Soup将复杂HTML文档转换成一个复杂的树形结构, 每个节点都是Python对象,所有对象可以归纳为4种: Tag , NavigableString , BeautifulSo ...

  2. linux下查看隐藏文件

    linux下查看隐藏文件的快捷键:Ctrl+H 命令:ls -a

  3. JS标签获取另一个页面传过来的href值

    a href=b.html?id=楼主>B页面</a>b.html中的获取函数:function getParam(){C1=window.location.href.split(& ...

  4. Word文档转Markdown插件(Windows)

    在线的转换,Shell脚本的转换都试过了,都没有原生Word文档集成的插件转换这么好用,并且没有Bug. 下载:http://www.writage.com/

  5. cart树剪枝

    当前子树的损失函数: $C_a(T) = C(T) + a|T|$, 其中$C(T)$为对训练数据的预测误差,$|T|$为树的叶子结点数目,反映模型的复杂度.对固定的$a$,一定存在使损失函数$C_a ...

  6. ReactNavtive框架教程(3)

    原文:http://www.raywenderlich.com/99473/introducing-react-native-building-apps-javascript 注意:全部图片放在了百度 ...

  7. BUPT复试专题—中位数(2014-2)

    题目描述 给定一个长度为N的非降数列,求数列的中位数.中位数:当数列的项数N为奇数吋,处于中间位置的变最值即为中位数:当N 为偶数时,中位数则为处于中间位置的两个数的平均数.   输入 输入数据第一行 ...

  8. Mysql学习之十二:JDBC连接数据库之DriverManager方法

    JDBC连接数据库 •创建一个以JDBC连接数据库的程序,包括7个步骤: 1.载入JDBC驱动程序: 在连接数据库之前.首先要载入想要连接的数据库的驱动到JVM(Java虚拟机). 这通过java.l ...

  9. ProFTPD配置匿名登录与文件夹訪问权限控制

    对ProFTPDserver配置匿名登录.         查看配置文件proftpd.conf.默认情况下配置文件里的.匿名登录配置User和Group均为ftp. 查看/etc/passwd确认用 ...

  10. Ubuntu搭建Android开发环境

    前言 由于迁移到新的笔记本,所以Android开发环境须要又一次配置了.android官网有配置教程,我正好回想一遍 配置Java环境 下载jdk.官网地址:http://www.oracle.com ...