Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## TL 了 。。。求指教

Posted by 150140 at 2018-10-17 22:02:03 on Problem 3468
```#include<cstdio>
#include<cstring>
typedef long long ll;
const int maxn=262144;
int node[maxn/2];
void pushup(int rt)
{
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void bulid(int l,int r,int rt)
{
if(l==r)
{
sum[rt]=(ll)node[l];
return ;
}
int m=(l+r)>>1;
bulid(l,m,rt<<1);
bulid(m+1,r,rt<<1|1);
pushup(rt);
}
void pushdown(int rt,int ln,int rn)
{
{
}
}
void update(int L,int R,ll c,int l,int r,int rt)
{
if(l==r)
{
sum[rt]+=(ll)c*(r-l+1);
return ;
}
int m=(l+r)>>1;
pushdown(rt,m-l+1,r-m);
if(L<=m)
update(L,R,c,l,m,rt<<1);
if(R>m)
update(L,R,c,m+1,r,rt<<1|1);
pushup(rt);
}
ll query(int L,int R,int l,int r,int rt)
{
if(L<=l && R>=r)
return sum[rt];
int m=(l+r)>>1;
pushdown(rt,m-l+1,r-m);
ll ans=0;
if(L<=m)
ans+=query(L,R,l,m,rt<<1);
if(R>m)
ans+=query(L,R,m+1,r,rt<<1|1);
return ans;
}
int main()
{
int n,q,x,y;
char ch;
ll z;
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++)
scanf("%d",&node[i]);
bulid(1,n,1);
for(int i=0;i<q;i++)
{
getchar();
scanf("%c",&ch);
if(ch=='Q')
{
scanf("%d%d",&x,&y);
printf("%lld\n",query(x,y,1,n,1));
}
else if(ch=='C')
{
scanf("%d%d%lld",&x,&y,&z);
update(x,y,z,1,n,1);
}
}
return 0;
}
```

Followed by: