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 MP make_pair
#define F first
#define PB push_back
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 3e5 + 4;
int a[maxn], pos[maxn];
int main (){
ios_base::sync_with_stdio(false);
int n, st;
cin >> n >> st;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = n - a[i] + 1;
}
int ptr1 = st - 1, ptr2 = st + 1, tmp = 1;
while (ptr1 >= 1 or ptr2 <= n) {
if (ptr1 < 1) {
pos[ptr2 ++] = tmp ++;
}
else if (ptr2 > n) {
pos[ptr1 --] = tmp ++;
}
else {
if (a[ptr1] > a[ptr2]) {
pos[ptr1 --] = tmp ++;
}
else {
pos[ptr2 ++] = tmp ++;
}
}
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
char type;
cin >> type;
if (type == 'F') {
int idx;
cin >> idx;
cout << pos[idx] << '\n';
}
else {
int idx, x;
cin >> idx >> x;
for (int j = 1; j <= n; j++) {
if (a[i] >= x and a[i] < a[idx]) {
a[i] ++;
}
}
a[idx] = x;
int ptr1 = st - 1, ptr2 = st + 1, tmp = 1;
while (ptr1 >= 1 or ptr2 <= n) {
if (ptr1 < 1) {
pos[ptr2 ++] = tmp ++;
}
else if (ptr2 > n) {
pos[ptr1 --] = tmp ++;
}
else {
if (a[ptr1] > a[ptr2]) {
pos[ptr1 --] = tmp ++;
}
else {
pos[ptr2 ++] = tmp ++;
}
}
}
}
}
}
| # | 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... |