This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int N, K, l, r, m, S;
int tempArr[4];
int *A;
cin >> N >> K;
A = new int[N];
int Temp;
for(int i = N;i>0;i--){
cin >> Temp;
A[N-i] = Temp;
}
int Q;
cin >> Q;
int *permList;
permList = new int[K];
int extraTemp;
int type;
int a1, a2, k_add;
for(int t = Q;t>0;t--){
cin >> type;
switch (type){
case 1:
if(K!=1){
for(int i=0;i<K;i++){
cin >> Temp;
permList[i] = Temp-1;
}
Temp = A[permList[0]];
for(int i=K-1;i>=0;i--){
extraTemp = Temp;
Temp = A[permList[i]];
A[permList[i]] = extraTemp;
}
}else{
cin >> Temp;
}
/*for(int i = 0;i<N;i++){
cout << A[i] << ' ';8
}
cout << '\n';*/
break;
case 2:
cin >> l >> r >> m;
//cout << l << ' ' << r << '\n';
S = 0;
for(int i=l-1;i<r;i++){
/*
tempArr[0]=i-l+2;
tempArr[1]=m;
tempArr[2]=r-i;
tempArr[3]=r-l-m+2;
S+=A[i]*(*min_element(begin(tempArr), end(tempArr)));
*/
a1=max(i+m-r,0);
a2=max(l-i+m-2,0);
k_add=m-a1-a2;
S+=A[i]*k_add;
//cout << S << '\n';
}
cout << S << endl;
}
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:7:9: warning: unused variable 'tempArr' [-Wunused-variable]
7 | int tempArr[4];
| ^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |