이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl "\n"
const int mod = (int) 1e9+7;
const int N=2e5+5;
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,a; cin>>n>>a;
int d[n+5],opd[n+5];
for (int i=1;i<=n;i++) {
cin>>d[i];
opd[d[i]]=i;
}
int when[n+5];
when[a]=0;
int l=a-1,r=a+1,time=1;
while (time<n) {
if (l>=1 && ((r>n) || (r<=n && d[l]<d[r]))) {
when[l]=time; time++; l--;
}
if (r<=n && ((l<1) || (l>=1 && d[r]<d[l]))) {
when[r]=time; time++; r++;
}
}
int q; cin>>q;
while (q--) {
char c; cin>>c;
if (c=='F') {
int x; cin>>x;
cout<<when[x]<<endl;
}
else {
int x,nw; cin>>x>>nw;
nw=n-(nw-1);
for (int i=d[x]+1;i<=nw;i++) {
d[opd[i]]--; opd[d[opd[i]]]=opd[i];
}
d[x]=nw;
opd[d[x]]=x;
//for (int i=1;i<=n;i++) cout<<d[i]<<' '; cout<<endl;
int l=a-1,r=a+1,time=1;
while (time<n) {
if (l>=1 && ((r>n) || (r<=n && d[l]<d[r]))) {
when[l]=time; time++; l--;
}
if (r<=n && ((l<1) || (l>=1 && d[r]<d[l]))) {
when[r]=time; time++; r++;
}
}
}
}
}
# | 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... |