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 <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=1e4+5;
int a[maxn];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, x;
cin >> n >> x;
x--;
for(int i=0; i<n; i++){
cin >> a[i];
}
int q;
cin >> q;
char c;
int e, f;
int pos, br;
int l, d;
for(int i=0; i<q; i++){
cin >> c >> e;
e--;
if(c=='F'){
pos=x;
br=0;
l=pos-1;
d=pos+1;
while(pos!=e){
br++;
if(l==-1 || (d<n && a[l]>a[d])){
pos=d;
d++;
}
else{
pos=l;
l--;
}
}
cout << br << '\n';
}
else{
cin >> f;
f--;
f=n-f;
if(f>a[e]){
for(int j=0; j<n; j++){
if(a[j]>a[e] && a[j]<=f){
a[j]--;
}
}
a[e]=f;
}
else if(f<a[e]){
for(int j=0; j<n; j++){
if(a[j]>=f && a[j]<a[e]){
a[j]++;
}
a[e]=f;
}
}
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |