#include <bits/stdc++.h>
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
//#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
using namespace std;
const int N=3e5+100;
ll val[N];
ll b[N];
ll a,n;
void solve(){
b[a]=0;
val[0]=1e9;
val[n+1]=1e9;
ll l=a-1,r=a+1;
for (int i=1;i<n;i++){
if (val[l]<val[r]){
b[l]=i;
l--;
}
else{
b[r]=i;
r++;
}
}
}
int32_t main(){
sync;
cin >> n >> a;
for (int i=1;i<=n;i++){
cin >> val[i];
}
solve();
ll q;
cin >> q;
for (int i=0;i<q;i++){
char c;
cin >> c;
if (c=='E'){
ll id,cnt;
cin >> id >> cnt;
cnt=n-cnt+1;
if (cnt>=val[id]){
for (int j=1;j<=n;j++){
if (val[j]<=cnt && val[j]>=val[id] && j!=id) val[j]--;
}
}
else{
for (int j=1;j<=n;j++){
if (val[j]>=cnt && val[j]<=val[id] && j!=id) val[j]++;
}
}
val[id]=cnt;
solve();
}
else{
ll id;
cin >> id;
cout << b[id] << endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
16 ms |
376 KB |
Output is correct |
5 |
Correct |
285 ms |
732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2045 ms |
1216 KB |
Time limit exceeded |
2 |
Execution timed out |
2053 ms |
1480 KB |
Time limit exceeded |
3 |
Execution timed out |
2037 ms |
1400 KB |
Time limit exceeded |
4 |
Execution timed out |
2019 ms |
1480 KB |
Time limit exceeded |
5 |
Execution timed out |
2047 ms |
504 KB |
Time limit exceeded |
6 |
Execution timed out |
2086 ms |
504 KB |
Time limit exceeded |
7 |
Execution timed out |
2017 ms |
508 KB |
Time limit exceeded |
8 |
Execution timed out |
2095 ms |
504 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
1688 KB |
Output is correct |
2 |
Correct |
52 ms |
1660 KB |
Output is correct |
3 |
Correct |
50 ms |
1528 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
149 ms |
3108 KB |
Output is correct |
6 |
Correct |
136 ms |
3036 KB |
Output is correct |
7 |
Correct |
96 ms |
2792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
439 ms |
584 KB |
Output is correct |
2 |
Correct |
718 ms |
604 KB |
Output is correct |
3 |
Execution timed out |
2083 ms |
932 KB |
Time limit exceeded |
4 |
Execution timed out |
2092 ms |
1100 KB |
Time limit exceeded |
5 |
Correct |
876 ms |
916 KB |
Output is correct |
6 |
Execution timed out |
2055 ms |
1016 KB |
Time limit exceeded |
7 |
Execution timed out |
2023 ms |
916 KB |
Time limit exceeded |
8 |
Execution timed out |
2058 ms |
1144 KB |
Time limit exceeded |
9 |
Execution timed out |
2033 ms |
2424 KB |
Time limit exceeded |
10 |
Execution timed out |
2057 ms |
1484 KB |
Time limit exceeded |
11 |
Execution timed out |
2063 ms |
900 KB |
Time limit exceeded |
12 |
Execution timed out |
2057 ms |
1912 KB |
Time limit exceeded |
13 |
Execution timed out |
2008 ms |
2556 KB |
Time limit exceeded |