#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 ++;
}
}
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
420 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2033 ms |
1668 KB |
Time limit exceeded |
2 |
Execution timed out |
2040 ms |
2740 KB |
Time limit exceeded |
3 |
Execution timed out |
2065 ms |
3676 KB |
Time limit exceeded |
4 |
Execution timed out |
2064 ms |
4832 KB |
Time limit exceeded |
5 |
Execution timed out |
2061 ms |
5676 KB |
Time limit exceeded |
6 |
Execution timed out |
2073 ms |
6188 KB |
Time limit exceeded |
7 |
Execution timed out |
2063 ms |
6856 KB |
Time limit exceeded |
8 |
Execution timed out |
2059 ms |
7608 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
216 ms |
10280 KB |
Output isn't correct |
2 |
Incorrect |
219 ms |
11400 KB |
Output isn't correct |
3 |
Incorrect |
202 ms |
12716 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
12716 KB |
Output isn't correct |
5 |
Incorrect |
259 ms |
16688 KB |
Output isn't correct |
6 |
Incorrect |
260 ms |
18944 KB |
Output isn't correct |
7 |
Incorrect |
246 ms |
21292 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
219 ms |
21292 KB |
Output isn't correct |
2 |
Incorrect |
340 ms |
21292 KB |
Output isn't correct |
3 |
Execution timed out |
2054 ms |
21304 KB |
Time limit exceeded |
4 |
Execution timed out |
2052 ms |
22032 KB |
Time limit exceeded |
5 |
Incorrect |
533 ms |
22816 KB |
Output isn't correct |
6 |
Execution timed out |
2054 ms |
24032 KB |
Time limit exceeded |
7 |
Execution timed out |
2065 ms |
25412 KB |
Time limit exceeded |
8 |
Execution timed out |
2058 ms |
26324 KB |
Time limit exceeded |
9 |
Execution timed out |
2056 ms |
29512 KB |
Time limit exceeded |
10 |
Runtime error |
1022 ms |
30772 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
11 |
Execution timed out |
2058 ms |
31504 KB |
Time limit exceeded |
12 |
Execution timed out |
2057 ms |
34368 KB |
Time limit exceeded |
13 |
Execution timed out |
2059 ms |
36716 KB |
Time limit exceeded |