#include <bits/stdc++.h>
using namespace std;
#define N 1000000
#define ll long long
vector<ll> lista(N);
ll n;
void update(int p, ll value){
lista[p]=value;
}
ll sum2(int m, int begin, int end){
ll result=0;
for(int i=begin-1;i<begin+m-1;i++){
result+=lista[i];
}
ll constantres=result;
for(int i=begin;i<end-m+1;i++){
constantres-=lista[i-1];
constantres+=lista[i+m-1];
result+=constantres;
}
return result;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
ll q,k;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>lista[i];
}
cin>>q;
for(int i=0;i<q;i++){
short c;
cin>>c;
if(c==1){
int a;
cin>>a;
int first=lista[a-1];
int b=a;
for(int i=0;i<k-1;i++){
int d=b;
cin>>b;
update(d-1,lista[b-1]);
}
update(b-1,first);
}
else if(c==2){
int a,b,m;
cin>>a>>b>>m;
cout<<sum2(m,a,b)<<'\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8148 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Correct |
9 ms |
8148 KB |
Output is correct |
5 |
Correct |
11 ms |
8148 KB |
Output is correct |
6 |
Correct |
16 ms |
8148 KB |
Output is correct |
7 |
Correct |
23 ms |
8204 KB |
Output is correct |
8 |
Correct |
28 ms |
8320 KB |
Output is correct |
9 |
Correct |
50 ms |
8196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
210 ms |
8416 KB |
Output is correct |
2 |
Correct |
370 ms |
8564 KB |
Output is correct |
3 |
Correct |
662 ms |
8648 KB |
Output is correct |
4 |
Execution timed out |
2084 ms |
9156 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
846 ms |
8640 KB |
Output is correct |
2 |
Execution timed out |
2067 ms |
8960 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |