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 ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll mod=1e9+7;
const ll maxn=5e5+500;
const ll inf=1e9+900;
const ll sq=10;
ll p[maxn];
ll n,a;
ll find_max(ll e){
ll l=e;
ll r=a;
if(r<l){
swap(l,r);
}
ll ans=0;
for(ll i=l;i<=r;i++){
if(i!=a){
ans=max(ans,p[i]);
}
}
return ans;
}
ll find_first_high(ll x,ll f){
for(ll i=a+f;;i+=f){
if(p[i]>x)return i;
}
return 0;
}
void update(ll x,ll v){
ll a=p[x];
ll b=n-v+1;
for(ll i=1;i<=n;i++){
if(p[i]==a){
p[i]=b;
}
else if(a<p[i] && p[i]<=b){
p[i]--;
}
}
}
int main(){
cin>>n>>a;
p[0]=n+1;
p[n+1]=n+2;
for(ll i=1;i<=n;i++){
cin>>p[i];
}
ll q;
cin>>q;
for(ll i=0;i<q;i++){
char c;
cin>>c;
if(c=='F'){
ll e;
cin>>e;
ll mi=find_max(e);
ll o;
if(e==a){
cout<<0<<endl;
continue;
}
if(e<a){
o=find_first_high(mi,1);
}else{
o=find_first_high(mi,-1);
}
cout<<abs(o-e)-1<<endl;
}else{
ll x,v;
cin>>x>>v;
update(x,v);
}
}
}
# | 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... |