#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(a<p[i] && p[i]<=b){
p[i]--;
}
}
}
int main(){
cin>>n>>a;
p[0]=n+1;
p[n+1]=n+2;
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:71:6: warning: 'o' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(o==a){
^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
18 ms |
384 KB |
Output is correct |
5 |
Correct |
215 ms |
568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2057 ms |
384 KB |
Time limit exceeded |
2 |
Execution timed out |
2043 ms |
384 KB |
Time limit exceeded |
3 |
Execution timed out |
2043 ms |
384 KB |
Time limit exceeded |
4 |
Execution timed out |
2039 ms |
384 KB |
Time limit exceeded |
5 |
Execution timed out |
2040 ms |
564 KB |
Time limit exceeded |
6 |
Execution timed out |
2033 ms |
512 KB |
Time limit exceeded |
7 |
Execution timed out |
2071 ms |
512 KB |
Time limit exceeded |
8 |
Execution timed out |
2076 ms |
484 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2032 ms |
1492 KB |
Time limit exceeded |
2 |
Execution timed out |
2015 ms |
1524 KB |
Time limit exceeded |
3 |
Correct |
1845 ms |
1660 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Execution timed out |
2020 ms |
2672 KB |
Time limit exceeded |
6 |
Execution timed out |
2031 ms |
2596 KB |
Time limit exceeded |
7 |
Execution timed out |
2044 ms |
2872 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
375 ms |
568 KB |
Output is correct |
2 |
Correct |
576 ms |
640 KB |
Output is correct |
3 |
Execution timed out |
2031 ms |
1016 KB |
Time limit exceeded |
4 |
Execution timed out |
2037 ms |
1164 KB |
Time limit exceeded |
5 |
Correct |
780 ms |
816 KB |
Output is correct |
6 |
Execution timed out |
2025 ms |
1272 KB |
Time limit exceeded |
7 |
Execution timed out |
2045 ms |
788 KB |
Time limit exceeded |
8 |
Execution timed out |
2009 ms |
1144 KB |
Time limit exceeded |
9 |
Execution timed out |
2059 ms |
2480 KB |
Time limit exceeded |
10 |
Execution timed out |
2058 ms |
1280 KB |
Time limit exceeded |
11 |
Execution timed out |
2041 ms |
844 KB |
Time limit exceeded |
12 |
Execution timed out |
2009 ms |
1948 KB |
Time limit exceeded |
13 |
Execution timed out |
2005 ms |
2348 KB |
Time limit exceeded |