Total Submission(s) : 77 Accepted Submission(s) : 19
You have N integers, A1,A2, ... ,AN. You need to deal with two kinds of operations. One type of operation is to add some given number to each number in a given interval. The other is to ask for the sum of numbers in a given interval.
10 5 1 2 3 4 5 6 7 8 9 10 Q 4 4 Q 1 10 Q 2 4 C 3 6 3 Q 2 4
4 55 9 15
#if 0
#include<iostream>
#include<cstring>
#include<stdio.h>
using namespace std;
const int MAXN=100000+50;
typedef long long ll;
ll b[MAXN],c[MAXN];
ll a[MAXN];
int lowbit(ll x)
{
return x&(-x);
}
void add_B(ll *a,ll x,ll v)
{
for( ; x>0; x-=lowbit(x))
a[x]+=v;
}
ll sum_B(ll *a,ll x)
{
ll s=0;
for(; x<MAXN; x+=lowbit(x))
{
s+=a[x];
}
return s;
}
void add_C(ll *a,ll x,ll v)
{
for( ; x<MAXN; x+=lowbit(x))
{
a[x]+=v;
}
}
ll sum_C(ll *a, ll x)
{
ll s=0;
for( ; x>0; x-=lowbit(x))
{
s+=a[x];
}
return s;
}
void add(ll x,ll v)
{
add_B(b,x-1,v);
add_C(c,x,v*x);
}
void go_add(ll a,ll b,ll v)
{
add(b,v);
add(a-1,-v); //
}
ll sum(ll x)
{
return sum_C(c,x)+sum_B(b,x)*x;
}
ll go_sum(ll a,ll b)
{
return sum(b)-sum(a-1);
}
int main()
{
ll n,t;
char ssc;
scanf("%lld%lld",&n,&t);
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
memset(c,0,sizeof(c));
for(int i=3; i<=n+2; i++)
{
ll x;
scanf("%lld",&x);
go_add(i,i,x);
}
while(t--)
{
cin>>ssc;
if(ssc=='Q')
{
ll ai,bi;
scanf("%lld%lld",&ai,&bi);
ai+=2;
bi+=2;
printf("%lld\n",go_sum(ai,bi));
}
else if(ssc=='C')
{
ll ai,bi;
ll v;
scanf("%lld%lld%lld",&ai,&bi,&v);
ai+=2;
bi+=2;
go_add(ai,bi,v);
}
}
}
#endif
1542



被折叠的 条评论
为什么被折叠?



