#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. Codeforces Round #268 (Div. 2) D. Two Sets [stl - set + 暴力]

    8161957                 2014-10-10 06:12:37     njczy2010     D - Two Sets             GNU C++     A ...

  2. python操作excel--生成图表

    [问题] 想要折腾Python中的Excel中的图标,Chart,Graph. [解决过程] 1.参考: use python to generate graph in excel 说是可以用pywi ...

  3. meta标签集

    html中的meta总结: 0.声明文档使用的字符编码: <meta charset='utf-8'/> 1.优先使用 IE 最新版本和 Chrome : <meta http-eq ...

  4. python在webservice接口测试中的应用

    接口测试第二波,webservice接口来咯,欢迎各位小伙伴吐槽~本次拿免费的互联网国内手机号码归属地查询WEB服务webservice接口做例子,当然有很多免费webservice接口可以供大家使用 ...

  5. HUNAN 11562 The Triangle Division of the Convex Polygon(大卡特兰数)

    http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11562&courseid=0 求n边形分解成三角形的 ...

  6. 迁移桌面程序到MS Store(8)——通过APPX下载Win32Component

    在上一篇<迁移桌面程序到MS Store(7)——APPX + Service>中,我们提到将desktop application拆分成UI Client+Service两部分.其中UI ...

  7. chromium爱好者不可错过的一个开源分支

    这次我要推荐下http://bloomberg.github.com/chromium.bb, 名字就叫chromium.bb,特点是专门的windows ports,关键是极大的简化了原版chrom ...

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

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

  9. openERP邮件(发信、收信)

    openERP里的邮件处理主要有个2个模块处理 mail -核心 fetchmail -接收邮件     Alias domain和alias name     配置domain alias. Set ...

  10. Android自己主动升级框架

    先看效果 使用 package com.ydl.versionupdate; import android.app.Activity; import android.content.Context; ...