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 <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define printv(a, b) {\
for(auto pv : a) b << pv << " ";\
b << "\n";\
}
using namespace std;
using pii = pair<int, int>;
ostream& operator<<(ostream& o, pii p){
return o << '(' << p.F << ',' << p.S << ')';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, a;
cin >> n >> a;
vector<int> d(n + 1);
map<int, int, greater<>> rk;
for(int i = 1; i <= n; i++){
cin >> d[i];
rk[d[i]] = i;
}
//printv(d, cerr);
//printv(rk, cerr);
vector<int> pos(n + 1);
int q;
cin >> q;
while(q--){
char c;
cin >> c;
if(c == 'F'){
int b;
cin >> b;
int l = a, r = a;
pos[a] = 1;
for(int i = 2; i <= n; i++){
if(r == n){
l--;
pos[l] = i;
//cerr << l << " " << i << "\n";
}
else if(l == 1){
r++;
pos[r] = i;
//cerr << r << " " << i << "\n";
}
else if(d[l - 1] < d[r + 1]){
l--;
pos[l] = i;
//cerr << l << " " << i << "\n";
}
else{
r++;
pos[r] = i;
//cerr << r << " " << i << "\n";
}
}
cout << pos[b] - 1 << "\n";
continue;
}
int b, e;
cin >> b >> e;
vector<int> tmp;
for(int i = 0; i < e - 1; i++){
tmp.eb(rk.begin()->S);
rk.erase(rk.begin());
}
tmp.eb(b);
rk.erase(d[b]);
while(!tmp.empty()){
int now = tmp.back();
tmp.pop_back();
d[now] = rk.empty() ? 1 : rk.begin()->F + 1;
rk[d[now]] = now;
}
}
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... |