QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85230 | #5687. 速战速决 | liaopengfei | RE | 0ms | 0kb | C++14 | 1.6kb | 2023-03-07 12:31:12 | 2023-03-07 12:31:14 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
const int N = 6e5 + 15;
map<int,int> q;
int n,now[N],b[N],a[N],cur,ans[N],bf[N],c[N];
void doit(int x){
int siz=0,bt=0;
For(i,x,n+x-1){
if(now[b[i]]==1||siz==0){
ans[i]=cur;
if(siz==0){
bf[++bt]=cur; now[cur]=1; q[cur]--; siz=1;
}else{
while(bf[bt]!=cur)
now[bf[bt]]=0,q[bf[bt]]++,--bt;
now[cur]=0,q[cur]++,--bt;
siz=0;
}
}else{
int t1=q.begin()->first,t2=q.rbegin()->first;
if(t1==b[i]){
ans[i]=t2;
if(now[t2]){
while(bf[bt]!=t2)
now[bf[bt]]=0,q[bf[bt]]++,--bt;
now[t2]=0,q[t2]++,--bt;
continue;
}
bf[++bt]=t2; now[t2]=1; q[t2]--;
if(!q[t2]) q.erase(t2);
}else{
ans[i]=t1;
if(now[t1]){
while(bf[bt]!=t1)
now[bf[bt]]=0,q[bf[bt]]++,--bt;
now[t1]=0,q[t1]++,--bt;
}
else{
bf[++bt]=t1; now[t1]=1; q[t1]--; ans[i]=t1;
if(!q[t1]) q.erase(t1);
}
}
}
bf[++bt]=b[i];
now[b[i]]=1;
// For(j,1,bt) cout<<bf[j]<<" ";cout<<bt<<bt<<" "<<i<<endl;
}
For(i,x,n+x-1) printf("%d ",ans[i]);
}
int main(){
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout);
scanf("%d",&n);
bool qq=0;
For(i,1,n){
scanf("%d",&b[i]);
c[b[i]]++;
if(c[b[i]]>1) qq=1;
}
For(i,1,n){
if(c[i]==0) cur=i,q[i]=2;
if(c[i]==1) q[i]=1;
}
if(qq){
printf("%d\n",n);
doit(1);
}else{
if(n==1){
printf("-1\n");
return 0;
}
printf("%d\n%d %d ",n+2,b[2],b[1]);
b[n+1]=b[n+2]=b[2]; cur=b[1]; q[b[1]]++; q.erase(b[2]);
doit(3);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
249665 195633 37425 205189 128330 159707 98406 111454 30346 158516 121742 107964 50039 201395 16843 182333 60177 195166 188257 172666 71779 157060 237654 123572 145065 57507 152240 187931 5706 191077 214174 70950 71272 172767 61529 85258 74139 44633 181186 223348 222711 19237 239887 20487 84130 1392...