# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
101596 | rainy | Cake (CEOI14_cake) | C++14 | 2100 ms | 26348 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>
#include<map>
#define MAXN 250005
using namespace std;
int N,A,Q,d[MAXN],od[MAXN];
map<int,int>dtp;
int main(){
scanf("%d%d",&N,&A);
for(int i=1;i<=N;i++){
scanf("%d",&d[i]);
dtp[d[i]]=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;
map<int,int>temp=dtp;
dtp[d[I]]=I;
for(int j=orr+1;j<d[I];j++){
int pos=temp[j];
d[pos]--;
dtp[j]=pos;
}
}
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;
map<int,int>temp=dtp;
dtp[d[I]]=I;
for(int j=orr+1;j<d[I];j++){
int pos=temp[j];
d[pos]--;
dtp[j]=pos;
}
}
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... |