#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin>>N>>K;
vector<int>A(N);
for(int i=0;i<N;i++)
cin>>A[i];
int Q;
cin>>Q;
while(Q--){
string type;
cin>>type;
if(type=="1") {
vector<int>indices(K);
for(int i=0;i<K;i++) {
cin>>indices[i];
indices[i]--;
}
int temp=A[indices[0]];
for(int i=0;i<K-1;i++){
A[indices[i]]=A[indices[i+1]];
}
A[indices[K-1]]=temp;
} else if(type=="2"){
int l,r,m;
cin>>l>>r>>m;
l--;
r--;
long long total=0;
int length=r-l+1;
for(int i=0;i<length;i++) {
int x=l+i;
int w=min({i+1,m,length-i});
total+=1LL*A[x]*w;
}
cout<<total<<"\n";
}
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |