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 vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define fi first
#define se second
#define INF 1e7
#define unsigned u
#define eps 1e-18
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9+7;
const int nax = 100005;
vi s;
int main() {
optimise;
int n,start;
cin >> n >> start;
start--;
for (int i = 0; i < n; ++i)
{
int a;
cin >> a;
s.pb(a);
}
int q;
cin >> q;
while(q--){
char be;
cin >> be;
if(be == 'F'){
int a;
cin >> a;
a--;
int l, r;
if(start > 0) l = start-1;
else l = -1;
if(start < n-1) r = start+1;
else r = -1;
int cur = start, i = 0;
while(cur != a){
//cout << cur << " ";
if(l==-1) cur = r, r++;
else if(r==-1) cur = l, l--;
else if(s[r] < s[l]){
cur = r;
r++;
} else if(s[r] > s[l]){
cur = l;
l--;
}
if(r == n) r = -1;
i++;
}
cout << i << endl;
} else {
int a,b;
cin >> a >> b;
a--;
b = n-b+1;
for (int i = 0; i < n; ++i)
{
if(s[i] <= b && s[i]>s[a])
s[i]--;
}
s[a] = b;
}
}
}
# | 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... |