#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pii pair<int,int>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0) using namespace std; const double g=10.0,eps=1e-;
const int N=+,maxn=+,inf=0x3f3f3f3f; ll value[N<<],lazy[N<<];
void build(int l,int r,int rt)
{
lazy[rt]=;
if(l==r)
{
scanf("%lld",&value[rt]);
return ;
}
int m=(l+r)>>;
build(ls);
build(rs);
value[rt]=value[rt<<]+value[rt<<|];
}
void update(int L,int R,ll c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
lazy[rt]+=c;
//value[rt]+=c*(r-l+1);
return ;
}
int m=(l+r)>>;
if(L<=m)update(L,R,c,ls);
if(m<R)update(L,R,c,rs);
value[rt]=value[rt<<]+value[rt<<|]+lazy[rt<<]*(m-l+)+lazy[rt<<|]*(r-m);
}
ll query(int L,int R,ll add,int l,int r,int rt)
{
if(L<=l&&r<=R)
return (add+lazy[rt])*(r-l+)+value[rt];
int m=(l+r)>>;
ll ans=;
if(L<=m)ans+=query(L,R,add+lazy[rt],ls);
if(m<R)ans+=query(L,R,add+lazy[rt],rs);
return ans;
}
char s[];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
build(,n,);
while(m--)
{
scanf("%s",s);
if(s[]=='Q')
{
int l,r;
scanf("%d%d",&l,&r);
printf("%lld\n",query(l,r,,,n,));
}
else
{
int l,r;ll c;
scanf("%d%d%lld",&l,&r,&c);
update(l,r,c,,n,);
//printf("%d\n",query(1,n,0,1,n,1));
}
}
}
return ;
}
/********************
5
10000
1 1 1 1 1
w 1 3 2
w 2 4 3
w 1 5 1
********************/

标记永久化

最新文章

  1. GetLastError()函数返回值及含义
  2. 初始angular框架(1)
  3. Linux文件查看/编辑方法介绍
  4. [Mac]Mac中显示资源库文件夹
  5. 破解之寻找OEP[手动脱壳](2)
  6. hdoj 2054(A==B)
  7. Android studio教程:[6]创建多个Activity
  8. RHEL4-Partition Image系统备份(软件版)
  9. 59、jQuery初识
  10. 从此不再担心键盘遮住输入框OC(一)
  11. react-router v4中 HashRouter 和 BrowserRouter的使用
  12. WinForm关于更新程序的设计思路
  13. 1.4 flask request和session
  14. C# 实现拨号重连
  15. github建库不成功,不能用SVN上传
  16. A - 取(m堆)石子游戏
  17. P2257 YY的GCD(莫比乌斯反演)
  18. 《剑指offer》第五十八题(左旋转字符串)
  19. ArcGIS案例学习笔记-中国2000坐标转换实例
  20. 8.8 正睿暑期集训营 Day5

热门文章

  1. Python(数据库之数据类型)
  2. Linux命令之pip
  3. error:No resource found that matches the given name &#39;Theme.AppCompat.Light&#39;
  4. python DES3 加密解密
  5. Docker 网络之端口绑定
  6. 主机名 域名 网站名 URL
  7. kubernetes1.9 手动安装
  8. vue-cli中的build.js配置文件详细解析
  9. 60. Permutation Sequence(求全排列的第k个排列)
  10. 对Servlet请求或响应进行JMockit测试