# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101591 | rainy | Cake (CEOI14_cake) | C++14 | 2096 ms | 2936 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 250005
using namespace std;
int N,A,Q,d[MAXN],od[MAXN];
int main(){
scanf("%d%d",&N,&A);
for(int i=1;i<=N;i++)scanf("%d",&d[i]);
scanf("%d",&Q);
bool prevE=true;
int I=-1,E=-1;
for(int i=0;i<Q;i++){
char inp;
scanf(" %c",&inp);
if(inp=='E'){
if(prevE){
if(I!=-1&&E!=-1){
int orr=d[I];
d[I]=N-E+1;
for(int j=0;j<N;j++){
if(j!=I&&d[j]>orr&&d[j]<=d[I])d[j]--;
}
}
int s=A,e=A,sf=1;
while(!(s==1&&e==N)){
if(s==1){
e++;od[e]=sf;
}
else if(e==N){
s--;od[s]=sf;
}
else if(d[s-1]<d[e+1]){
s--;od[s]=sf;
}
else{
e++;od[e]=sf;
}
sf++;
}
}
prevE=true;
scanf("%d%d",&I,&E);
}
else{
int B;scanf("%d",&B);
if(prevE){
if(I!=-1&&E!=-1){
int orr=d[I];
d[I]=N-E+1;
for(int j=0;j<N;j++){
if(j!=I&&d[j]>orr&&d[j]<=d[I])d[j]--;
}
}
int s=A,e=A,sf=1;
while(!(s==1&&e==N)){
if(s==1){
e++;od[e]=sf;
}
else if(e==N){
s--;od[s]=sf;
}
else if(d[s-1]<d[e+1]){
s--;od[s]=sf;
}
else{
e++;od[e]=sf;
}
sf++;
}
}
printf("%d\n",od[B]);
prevE=false;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |