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>
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
//#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
using namespace std;
const int N=3e5+100;
ll val[N];
ll b[N];
ll a,n;
void solve(){
b[a]=0;
val[0]=1e9;
val[n+1]=1e9;
ll l=a-1,r=a+1;
for (int i=1;i<n;i++){
if (val[l]<val[r]){
b[l]=i;
l--;
}
else{
b[r]=i;
r++;
}
}
}
int32_t main(){
sync;
cin >> n >> a;
for (int i=1;i<=n;i++){
cin >> val[i];
}
solve();
ll q;
cin >> q;
for (int i=0;i<q;i++){
char c;
cin >> c;
if (c=='E'){
ll id,cnt;
cin >> id >> cnt;
cnt=n-cnt+1;
if (cnt>=val[id]){
for (int j=1;j<=n;j++){
if (val[j]<=cnt && val[j]>=val[id] && j!=id) val[j]--;
}
}
else{
for (int j=1;j<=n;j++){
if (val[j]>=cnt && val[j]<=val[id] && j!=id) val[j]++;
}
}
val[id]=cnt;
solve();
}
else{
ll id;
cin >> id;
cout << b[id] << endl;
}
}
}
# | 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... |