QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85238 | #5687. 速战速决 | liaopengfei | WA | 261ms | 22200kb | C++17 | 1.7kb | 2023-03-07 12:48:24 | 2023-03-07 12:48:25 |
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)
{
if(bf[bt]==cur) siz=0;
now[bf[bt]]=0,q[bf[bt]]++,--bt;
}
now[t2]=0,q[t2]++,--bt;
}else{
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)
{
if(bf[bt]==cur) siz=0;
now[bf[bt]]=0,q[bf[bt]]++,--bt;
}
now[t1]=0,q[t1]++,--bt;
}
else{
bf[++bt]=t1; now[t1]=1; q[t1]--;
if(!q[t1]) q.erase(t1);
}
}
}
bf[++bt]=b[i];
now[b[i]]=1;
}
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: 100
Accepted
time: 226ms
memory: 19300kb
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...
output:
249665 249660 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok Correct.
Test #2:
score: 0
Accepted
time: 231ms
memory: 22200kb
input:
289892 233602 170432 186700 23520 1359 74354 61778 97676 141808 279091 86618 107162 187289 270874 5771 92359 256248 59758 201034 111974 157736 29506 210946 178606 275526 119662 142498 119239 245490 9443 240901 72345 207797 759 91770 131534 189757 72201 5921 152878 237072 146758 101282 50083 61126 26...
output:
289892 245154 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 9...
result:
ok Correct.
Test #3:
score: 0
Accepted
time: 261ms
memory: 22132kb
input:
292190 145417 283887 12115 4326 45188 164129 14638 269369 233283 201793 241021 17606 90840 34917 16328 180328 261955 172583 181417 7942 223673 262641 28684 237776 243658 74833 205577 122527 28528 249819 73252 270152 117871 31565 204148 216504 192924 29203 143059 154759 104752 69112 166848 232567 962...
output:
292190 292190 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
result:
ok Correct.
Test #4:
score: 0
Accepted
time: 222ms
memory: 22004kb
input:
289638 179249 177210 122624 75928 106218 13899 249362 245081 212282 3125 52160 49231 77788 143892 158982 277667 242837 199352 19097 201259 164534 261237 201825 180668 58106 141543 286211 251784 6410 112507 51157 93955 107491 250456 58875 36203 234469 45239 283807 106103 197348 238937 162203 287869 1...
output:
289638 289636 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok Correct.
Test #5:
score: -100
Wrong Answer
time: 183ms
memory: 20408kb
input:
261175 113751 113751 247389 247389 106728 106728 249714 249714 128388 128388 216271 216271 163974 163974 245217 245217 246248 246248 51361 51361 176423 176423 19217 19217 197524 197524 251874 251874 112335 112335 160213 160213 60037 60037 250967 250967 187608 187608 214950 214950 208541 208541 25669...
output:
261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175 261175...
result:
FAIL card does not exist