#include<bits/stdc++.h>
using namespace std;
long long pre[100005];
long long n,k;
void update(long long l, long long r, long long x){
for(long long i=l; i<=r; i++){
long long tr=i;
while(tr<=n){
pre[tr]+=x;
tr+=tr&(-tr);
}
}
}
long long sum(long long l){
long long s=0;
while(l>0){
s+=pre[l];
l-=l&(-l);
}
return s;
}
int main(){
cin>>n>>k;
long long a[n+1];
long long prefix=0;
for(long long i=1; i<=n; i++){
cin>>a[i];
prefix+=a[i];
update(i,i, prefix);
}
long long q;
cin>>q;
while(q--){
long long x;
cin>>x;
if(x==1){
long long b[k+1];
for(long long i=1; i<=k; i++){
cin>>b[i];
}
update(b[k], n, a[b[k]]-a[b[1]]);
for(long long i=1; i<k; i++){
update(b[i], n, a[b[i]]-a[b[i+1]]);
}
continue;
}
long long l,r,m;
cin>>l>>r>>m;
long long s=0;
s+=sum(r)-sum(l+m-2);
s-=sum(r-m)-sum(l-2);
cout<<s<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
204 KB |
Output is correct |
3 |
Correct |
6 ms |
352 KB |
Output is correct |
4 |
Correct |
8 ms |
332 KB |
Output is correct |
5 |
Correct |
12 ms |
412 KB |
Output is correct |
6 |
Correct |
17 ms |
436 KB |
Output is correct |
7 |
Correct |
21 ms |
460 KB |
Output is correct |
8 |
Correct |
25 ms |
460 KB |
Output is correct |
9 |
Correct |
45 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
147 ms |
840 KB |
Output is correct |
2 |
Correct |
292 ms |
1092 KB |
Output is correct |
3 |
Correct |
508 ms |
1460 KB |
Output is correct |
4 |
Correct |
1350 ms |
2424 KB |
Output is correct |
5 |
Execution timed out |
2090 ms |
2808 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2075 ms |
1204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |