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

必须ac

Posted by 080528lj at 2021-08-26 16:09:37 on Problem 3468 and last updated at 2021-08-26 16:10:03
```就是一道树状数组
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

const int N=100010;
int a[N];
int n,m;
typedef long long LL;
LL c[2][N];
LL s[N];

int lowbit(int x)
{
return x&-x;
}

LL sum(int k,int x)
{
LL ans=0;
for(int i=x;i;i-=lowbit(i)) ans+=c[k][i];
return ans;
}

{
for(int i=x;i<=n;i+=lowbit(i))
{
c[k][i]+=y;
}
}

int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
s[i]=s[i-1]+a[i];
}
while(m--)
{
char op[2];
int l,r,d;
scanf("%s",op);
scanf("%d%d",&l,&r);
if(op[0]=='C')
{
scanf("%d",&d);
}
else
{
LL ans=s[r]+(r+1)*sum(0,r)-sum(1,r);
ans-=s[l-1]+l*sum(0,l-1)-sum(1,l-1);
cout<<ans<<endl;
}
}
return 0;
}
```

Followed by:

User ID:
Title:

Content: