#include<bits/stdc++.h>
using namespace std;
long long pre[10005];
long long n,k;
int b1[100005],b2[100005];
void update(int bit[], int v, int x){
while(v<=n){
bit[v]+=x;
v+=v&(-v);
}
}
void up(int l, int r, int x){
update(b1, l, x);
update(b1, r+1, -x);
update(b2, l, (l-1)*x);
update(b2, r+1, -r*x);
}
int presum(int bit[], int v){
int s=0;
while(v>0){
s+=bit[v];
v-=v&(-v);
}
return s;
}
int sum(int l,int r){
return presum(b1, r)*r-presum(b2, r)-(presum(b1, l-1)*(l-1)-presum(b2, l-1));
}
int main(){
cin>>n>>k;
long long a[n+1];
int prefix=0;
for(long long i=1; i<=n; i++){
cin>>a[i];
prefix+=a[i];
up(i,i,prefix);
}
long long q;
cin>>q;
while(q--){
long long x;
cin>>x;
if(x==1){
int b[k+1];
for(int i=1; i<=k; i++){
cin>>b[i];
}
up(b[k],n,a[b[1]]-a[b[k]]);
for(int i=1; i<k; i++){
up(b[i],n, a[b[i+1]]-a[b[i]] );
}
continue;
}
long long l,r,m;
cin>>l>>r>>m;
long long s=0;
s+=sum(l+m-1, r);
s-=sum(l-1, r-m);
cout<<s<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Incorrect |
5 ms |
332 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
53 ms |
692 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
145 ms |
1352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |