#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. 2-sat问题,输出方案,几种方法(赵爽的论文染色解法+其完全改进版)浅析 / POJ3683

    本文原创于  2014-02-12 09:26. 今复习之用,有新体会,故重新编辑. 2014-02-12 09:26: 2-sat之第二斩!昨天看了半天论文(赵爽的和俉昱的),终于看明白了!好激动有 ...

  2. java使用jxl,自动导出数据excle,quartz自动发送邮件

    =============JAVA后台代码===================== package com.qgc.service.autoSendMsg.AutoSendMsg import ja ...

  3. (5)Swing事件

    import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; publi ...

  4. css3的一些新属性及部分用法

    CSS3是CSS(层叠样式表)技术的升级版本,增加了很多新属性,我们在web开发中采用css3技术可以提高程序的性能以及用户体验.而且一般面试中会问到知道哪些新增加的属性,我们不可能将所有东西一一复述 ...

  5. 无法启动INTERNET连接共享。一个已经用IP地址配置的LAN连接需要自动IP地址

    提问者采纳   很简单 只要把你要共享的连接 192.168.0.1 0改成1 然后就可以共享了 共享后再改回来 就能上了 但是会出现IP冲突的~

  6. Spring实战Day6

    3.4 bean的作用域 Spring中bean的作用域 单例(Singleton):在整个应用中,只创建bean的一个实例. 原型(Prototype):每次注入或者通过Spring应用上下文获取的 ...

  7. TreeView 与 ListView

    ListView: viewStyle icon 大图标 list  列表,单列 report 报表 smallIcon 小图标 largeImage 与icon对应 smallImage 与saml ...

  8. ios下读取jason中的nsstring时间并本地化成中文gmt时间显示上午下午

    https://developer.apple.com/library/ios/qa/qa1480/_index.html - (NSDate *)dateFromString:(NSString * ...

  9. Android应用开发 WebView与服务器端的Js交互

    最近公司再添加功能的时候,有一部分功能是用的html,在一个浏览器或webview中展示出html即可.当然在这里我们当然用webview控件喽 WebApp的好处: 在应用里嵌套web的好处有这么几 ...

  10. Mysql 之配置文件my.cnf

    mysql配置文件为my.cnf,它所在位置根据安装时设定的. 当mysqld服务启动的时候,默认会按一定的顺序读取配置文件的. 1 2 3 [root@zhu2 ~]# /opt/mysql/lib ...