#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[x] < y && a[i] > a[x] && a[i] <= y) a[i]--;
if(a[x] > y && a[i] >= y && a[i] < a[x]) a[i]++;
}
a[x] = y;
//pr();
sol();
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
14 ms |
384 KB |
Output is correct |
5 |
Correct |
282 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2070 ms |
1604 KB |
Time limit exceeded |
2 |
Execution timed out |
2051 ms |
1748 KB |
Time limit exceeded |
3 |
Execution timed out |
2087 ms |
1604 KB |
Time limit exceeded |
4 |
Execution timed out |
2090 ms |
1672 KB |
Time limit exceeded |
5 |
Execution timed out |
2087 ms |
1272 KB |
Time limit exceeded |
6 |
Execution timed out |
2085 ms |
1288 KB |
Time limit exceeded |
7 |
Execution timed out |
2069 ms |
1272 KB |
Time limit exceeded |
8 |
Execution timed out |
2062 ms |
1400 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
3064 KB |
Output is correct |
2 |
Correct |
56 ms |
2936 KB |
Output is correct |
3 |
Correct |
47 ms |
2968 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
148 ms |
5364 KB |
Output is correct |
6 |
Incorrect |
127 ms |
5424 KB |
Output isn't correct |
7 |
Incorrect |
89 ms |
5240 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
423 ms |
960 KB |
Output is correct |
2 |
Correct |
689 ms |
888 KB |
Output is correct |
3 |
Execution timed out |
2059 ms |
1428 KB |
Time limit exceeded |
4 |
Execution timed out |
2035 ms |
1728 KB |
Time limit exceeded |
5 |
Correct |
816 ms |
1912 KB |
Output is correct |
6 |
Execution timed out |
2045 ms |
1832 KB |
Time limit exceeded |
7 |
Execution timed out |
2084 ms |
1656 KB |
Time limit exceeded |
8 |
Execution timed out |
2085 ms |
2168 KB |
Time limit exceeded |
9 |
Execution timed out |
2045 ms |
4136 KB |
Time limit exceeded |
10 |
Execution timed out |
2037 ms |
4328 KB |
Time limit exceeded |
11 |
Execution timed out |
2031 ms |
1508 KB |
Time limit exceeded |
12 |
Execution timed out |
2077 ms |
3496 KB |
Time limit exceeded |
13 |
Execution timed out |
2020 ms |
4392 KB |
Time limit exceeded |