#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 3e5 + 5;
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, s, q;
cin >> n >> s;
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
cin >> q;
while(q--) {
char t;
cin >> t;
if(t == 'F') {
int p;
cin >> p;
if(p == s) {
cout << 0 << '\n';
continue;
}
int l=s, r=s, ans=0;
while(l != p && r != p) {
ans++;
if(l - 1 == 0) r++;
else if(r + 1 > n) l--;
else if(v[l-1] < v[r+1]) l--;
else r++;
}
cout << ans << '\n';
} else {
int a, b;
cin >> a >> b;
int old = v[a];
v[a] = n - b + 1;
for(int i=1; i<a; i++) if(v[i] <= v[a] && old <= v[i]) v[i]--;
for(int i=a+1; i<=n; i++) if(v[i] <= v[a] && old <= v[i]) v[i]--;
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
496 KB |
Output is correct |
5 |
Correct |
178 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2019 ms |
2632 KB |
Time limit exceeded |
2 |
Execution timed out |
2037 ms |
3660 KB |
Time limit exceeded |
3 |
Execution timed out |
2049 ms |
3016 KB |
Time limit exceeded |
4 |
Execution timed out |
2035 ms |
3664 KB |
Time limit exceeded |
5 |
Execution timed out |
2077 ms |
1420 KB |
Time limit exceeded |
6 |
Execution timed out |
2050 ms |
1924 KB |
Time limit exceeded |
7 |
Execution timed out |
2083 ms |
1680 KB |
Time limit exceeded |
8 |
Execution timed out |
2076 ms |
2304 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2057 ms |
1860 KB |
Time limit exceeded |
2 |
Execution timed out |
2073 ms |
1876 KB |
Time limit exceeded |
3 |
Execution timed out |
2048 ms |
1856 KB |
Time limit exceeded |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Execution timed out |
2013 ms |
3208 KB |
Time limit exceeded |
6 |
Execution timed out |
2069 ms |
3220 KB |
Time limit exceeded |
7 |
Execution timed out |
2027 ms |
3160 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
281 ms |
852 KB |
Output is correct |
2 |
Correct |
444 ms |
832 KB |
Output is correct |
3 |
Execution timed out |
2061 ms |
1116 KB |
Time limit exceeded |
4 |
Execution timed out |
2065 ms |
1428 KB |
Time limit exceeded |
5 |
Correct |
504 ms |
1876 KB |
Output is correct |
6 |
Execution timed out |
2072 ms |
1332 KB |
Time limit exceeded |
7 |
Execution timed out |
2021 ms |
1740 KB |
Time limit exceeded |
8 |
Execution timed out |
2056 ms |
1876 KB |
Time limit exceeded |
9 |
Execution timed out |
2081 ms |
3164 KB |
Time limit exceeded |
10 |
Correct |
1722 ms |
5204 KB |
Output is correct |
11 |
Execution timed out |
2017 ms |
1360 KB |
Time limit exceeded |
12 |
Execution timed out |
2040 ms |
2756 KB |
Time limit exceeded |
13 |
Execution timed out |
2076 ms |
3164 KB |
Time limit exceeded |