이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second
const int mxn = 250001;
int n, k, q;
int a[mxn], b[mxn];
void sol(){
b[k] = 0;
for(int i = 1, l = k - 1, r = k + 1; i < n; i++){
if(a[l] < a[r]) b[l--] = i;
else b[r++] = i;
}
}
void pr(){
for(int i = 1; i <= n; i++) cout << a[i] << " ";
cout << endl;
for(int i = 1; i <= n; i++) cout << b[i] << " ";
cout << endl;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++){
cin >> a[i];
a[i]--;
}
a[0] = a[n + 1] = n;
sol();
//pr();
cin >> q;
while(q--){
char t;
cin >> t;
if(t == 'F'){
int x;
cin >> x;
cout << b[x] << endl;
}else{
int x, y;
cin >> x >> y;
y = n - y;
for(int i = 1; i <= n; i++){
if(a[i] >= min(a[x], y) && a[i] <= max(a[x], y)){
a[i] += 2 * (a[x] > y) - 1;
}
}
a[x] = y;
//pr();
sol();
}
}
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... |