#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll mod=1e9+7;
const ll maxn=5e5+500;
const ll inf=1e9+900;
const ll sq=10;
ll p[maxn];
ll n,a;
ll find_max(ll e){
ll l=e;
ll r=a;
if(r<l){
swap(l,r);
}
ll ans=0;
for(ll i=l;i<=r;i++){
if(i!=a){
ans=max(ans,p[i]);
}
}
return ans;
}
ll find_first_high(ll x,ll f){
for(ll i=a+f;;i+=f){
if(p[i]>x)return i;
}
return 0;
}
void update(ll a,ll b){
for(ll i=1;i<=n;i++){
if(p[i]==a){
p[i]=b;
}
else if(b<=p[i]){
p[i]++;
}
}
}
int main(){
cin>>n>>a;
p[0]=inf;
p[n+1]=inf;
for(ll i=1;i<=n;i++){
cin>>p[i];
}
ll q;
cin>>q;
for(ll i=0;i<q;i++){
char c;
cin>>c;
if(c=='F'){
ll e;
cin>>e;
ll mi=find_max(e);
ll o;
if(o==a){
cout<<0<<endl;
continue;
}
if(e<a){
o=find_first_high(mi,1);
}else{
o=find_first_high(mi,-1);
}
cout<<abs(o-e)-1<<endl;
}else{
ll x,v;
cin>>x>>v;
update(p[x],n-v+1);
}
}
}
Compilation message
cake.cpp: In function 'int main()':
cake.cpp:69:6: warning: 'o' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(o==a){
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2029 ms |
384 KB |
Time limit exceeded |
2 |
Execution timed out |
2041 ms |
356 KB |
Time limit exceeded |
3 |
Execution timed out |
2041 ms |
384 KB |
Time limit exceeded |
4 |
Execution timed out |
2044 ms |
384 KB |
Time limit exceeded |
5 |
Execution timed out |
2052 ms |
512 KB |
Time limit exceeded |
6 |
Execution timed out |
2056 ms |
512 KB |
Time limit exceeded |
7 |
Execution timed out |
2059 ms |
632 KB |
Time limit exceeded |
8 |
Execution timed out |
2039 ms |
512 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2036 ms |
1428 KB |
Time limit exceeded |
2 |
Execution timed out |
2056 ms |
1588 KB |
Time limit exceeded |
3 |
Incorrect |
915 ms |
1640 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
5 |
Execution timed out |
2063 ms |
2624 KB |
Time limit exceeded |
6 |
Execution timed out |
2040 ms |
2532 KB |
Time limit exceeded |
7 |
Execution timed out |
2033 ms |
2736 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
259 ms |
488 KB |
Output isn't correct |
2 |
Incorrect |
347 ms |
428 KB |
Output isn't correct |
3 |
Execution timed out |
2062 ms |
1016 KB |
Time limit exceeded |
4 |
Execution timed out |
2064 ms |
1148 KB |
Time limit exceeded |
5 |
Incorrect |
344 ms |
632 KB |
Output isn't correct |
6 |
Execution timed out |
2073 ms |
1020 KB |
Time limit exceeded |
7 |
Execution timed out |
2060 ms |
984 KB |
Time limit exceeded |
8 |
Execution timed out |
2080 ms |
1144 KB |
Time limit exceeded |
9 |
Execution timed out |
2064 ms |
2492 KB |
Time limit exceeded |
10 |
Incorrect |
1345 ms |
1656 KB |
Output isn't correct |
11 |
Execution timed out |
2064 ms |
812 KB |
Time limit exceeded |
12 |
Execution timed out |
2059 ms |
2296 KB |
Time limit exceeded |
13 |
Execution timed out |
2067 ms |
2552 KB |
Time limit exceeded |