#include<stdio.h>

#include<string.h>

#define N 100000

struct st{

 int x,y;

 __int64 yanchi,sum;

}a[N*4];

__int64 b[N];

void build(int t,int x,int y) {

 a[t].x=x;

 a[t].y=y;

 a[t].yanchi=0;

 if(x==y) {

  a[t].sum=b[x];

  return ;

 }

 int temp=t*2;

 int mid=(a[t].x+a[t].y)/2;

 build(temp,x,mid);

 build(temp+1,mid+1,y);

 a[t].sum=a[temp].sum+a[temp+1].sum;

 return ;

}

void change(int t,int x,int y,int z) {

 if(a[t].x==x&&a[t].y==y) {

  a[t].yanchi+=z;

  return ;

 }

 a[t].sum+=(y-x+1)*z;

 int temp=t*2;

 int mid=(a[t].x+a[t].y)/2;

 if(y<=mid)

  change(temp,x,y,z);

 else

  if(x>mid)

   change(temp+1,x,y,z);

  else {

   change(temp,x,mid,z);

   change(temp+1,mid+1,y,z);

  }

  return ;

}

__int64 qury(int t,int x,int y) {

 if(a[t].x==x&&a[t].y==y)

  return a[t].sum+(y-x+1)*a[t].yanchi;

   int temp=t<<1;

   int mid=(a[t].y+a[t].x)/2;

   a[temp+1].yanchi+=a[t].yanchi;

   a[temp].yanchi+=a[t].yanchi;

   a[t].sum+=a[t].yanchi*(a[t].y-a[t].x+1);

   a[t].yanchi=0;

   if(y<=mid)

    return qury(temp,x,y);

   else

    if(x>mid)

     return qury(temp+1,x,y);

    else

     return qury(temp,x,mid)+qury(temp+1,mid+1,y);

}

int main() {

 int i,j,k,n,m;

 char s[100];

 while(scanf("%d%d",&n,&m)!=EOF) {

  for(i=1;i<=n;i++)

   scanf("%I64d",&b[i]);

  build(1,1,n);

  while(m--) {

   scanf("%s",s);

   if(s[0]=='Q') {

    scanf("%d%d",&i,&j);

    printf("%I64d\n",qury(1,i,j));

   }

   else {

    scanf("%d%d%d",&i,&j,&k);

    change(1,i,j,k);

   }

}

 }

 return 0;

}

最新文章

  1. mybatis一对多关联
  2. Eclipse设置黑色主题
  3. Android Studio Jni 环境搭建
  4. ubuntu中管理用户和用户组
  5. 【转】Windows下搭建cvs服务器
  6. 8.2.1.8 IS NULL Optimization NULL 优化:
  7. WinDBG 技巧:如何生成Dump 文件(.dump 命令)
  8. Python3基础 内嵌函数 简单示例
  9. NewsDao
  10. js 关于日期,字符串转化
  11. python学习日记(python2/3区别补充,is / id/ encode str,bytes)
  12. vue父组件如何调用子组件的属性或方法
  13. 【演示】在CSS里用calc进行计算
  14. [原创]Burp Suite web应用程序渗透测试神器
  15. CentOS 7下NFS Server作rootfs时的兼容性问题
  16. java8 forEach Map List[转载]
  17. Tips for Navigating Large Game Code Bases
  18. CAS-自旋锁
  19. bzoj1625
  20. Water Tree(树链剖分+dfs时间戳)

热门文章

  1. Ionic之存储信息、取出存储信息、注销存储信息
  2. AJPFX总结Collection集合(上)
  3. JSP 错误处理方法
  4. QProcess执行带管道的shell命令
  5. 【算法】最长回文子串 longest palindrome substring
  6. 字符串翻转(java)
  7. python基础一 day2 数据类型
  8. 树状数组 || POJ 2352 Stars
  9. 【转】C# WinForm中的Label如何换行
  10. SQL Server 删除表的默认值约束