poj3468 A Simple Problem with Integers

#### 输入样例：

10 5
1 2 3 4 5 6 7 8 9 10
Q 4
Q 1
Q 2
C 1 6 3
Q 2


#### 输出样例：

4
1
2
5这次用线段树来实现，这里不带lazy标记的话时间复杂度降为O(n)
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long ll;
#define form(i,n) for(int i=1;i<=n;i++)
#define forn(i,n) for(int i=0;i<n;i++)
#define mst(a) memset(a,0,sizeof(a))
#define P pair<int,int>
#define wh(T) while(T--)
const int MAX_N=1e7+10;
const int N=1e5+90;
const int inf=1e8;
const int SIZE=100010;
struct SegmentTree{
int l,r;
#define l(x) tree[x].l
#define r(x) tree[x].r
#define sum(x) tree[x].sum
}tree[N*4];
int a[N],n,m;
void build(int p,int l,int r)//No.p, [l,r]
{
l(p)=l,r(p)=r;
if(l==r) { sum(p)=a[l]; return; }
int mid=(l+r)/2;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
sum(p)=sum(p*2)+sum(p*2+1);
}

{
{
}
}

void change(int p,int l,int r,int z)
{
if(l<=l(p)&&r>=r(p))
{
sum(p)+=(long long)z*(r(p)-l(p)+1);
return;
}
int mid=(l(p)+r(p))/2;
if(l<=mid) change(p*2,l,r,z);
if(r>mid) change(p*2+1,l,r,z);
sum(p)=sum(p*2)+sum(p*2+1);
}

long long ask(int p,int l,int r)
{
if(l<=l(p)&&r>=r(p)) return sum(p);
int mid=(l(p)+r(p))/2;
long long ans=0;
return ans;
}

int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
build(1,1,n);
while(m--)
{
char op[2]; int x,y,z;
scanf("%s%d%d",op,&x,&y);
if(op[0]=='C')
{
scanf("%d",&z);
change(1,x,y,z);
}
}