QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#549775 | #5665. AA Country and King Dreamoon | Tiga_Pilot_2# | WA | 35ms | 3556kb | C++20 | 3.6kb | 2024-09-06 21:16:14 | 2024-09-06 21:16:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i > (b); --i)
#define ar array
#define sz(x) (int) (x).size()
#define pii pair<int,int>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
typedef vector<int> vi;
#define all(x) (x).begin(), (x).end()
template<typename T>
void min_self(T& A, T B) {
A = min(A,B);
}
template<typename T>
void max_self(T& A, T B) {
A = max(A,B);
}
const int mxn=3e5;
int n,t;
int a[mxn*2-1];
void solve() {
cin >>n;
rep(i,0,n*2-1) {
cin >>a[i];
}
set<int> blm;
rep(i,1,n+1) {
blm.insert(i);
}
a[0] =1, a[n*2-2] = 1;
vi vl,vr;
int id0 = -1;
rep(i,0,n*2-1) {
if(a[i]==0) {
id0 = i;
break;
}
blm.erase(a[i]);
if(sz(vl)<2) {
vl.push_back(a[i]);
} else {
if(vl[sz(vl)-2]==a[i]) {
vl.pop_back();
} else {
vl.push_back(a[i]);
}
}
}
int id0r = -1;
per(i,n*2-2,-1) {
if(a[i]==0) {
id0r = i;
break;
}
blm.erase(a[i]);
if(sz(vr)<2) {
vr.push_back(a[i]);
} else {
if(vr[sz(vr)-2]==a[i]) {
vr.pop_back();
} else {
vr.push_back(a[i]);
}
}
}
vector<bool> fl(n+1,0),fr(n+1,0);
vi idl(n+1,-1), idr(n+1,-1);
rep(i,0,sz(vl)) {
fl[vl[i]] = 1;
idl[vl[i]] = i;
}
rep(i,0,sz(vr)) {
fr[vr[i]] = 1;
idr[vr[i]] = i;
}
auto prv = [&](int u) -> int {
// par, nxt. -1 if abis
if(fr[u]) {
int idru = idr[u];
idru++;
if(sz(vr)>idru) {
return vr[idru];
} else {
return -1;
}
} else {
int idlu = idl[u];
idlu--;
if(idlu>=0) {
return vl[idlu];
} else {
return -1;
}
}
};
if(id0!=-1) {
int x0=id0;
int u = vl.back();
int blmi = sz(blm)>0?(*blm.begin()):1e9;
int pr = prv(u);
while(pr!=-1 && pr<blmi && x0<=id0r) {
a[x0] = pr;
x0++;
u = pr;
pr = prv(u);
}
if(x0<=id0r) {
// blm_0,..
if(sz(blm)) {
if(u<blmi) {
for(auto blmu : blm) {
a[x0] = blmu;
x0++;
if(x0>id0r) break;
a[x0] = u;
x0++;
}
} else {
a[x0] = blmi;
x0++;
for(auto it = ++blm.begin();it!=blm.end();it++) {
a[x0] = *it;
x0++;
// if(x0>id0r) break;
a[x0] = blmi;
x0++;
}
if(x0<=id0r) {
a[x0] = u;
}
}
}
}
}
rep(i,0,n*2-1) {
cout <<a[i] <<" \n"[i==n*2-2];
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >>t;
while(t--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
9 5 1 2 3 2 0 2 1 5 1 5 1 2 3 0 0 2 1 5 1 5 1 2 0 0 0 2 1 5 1 5 1 2 0 0 0 0 1 5 1 5 1 0 0 0 0 0 1 5 1 5 1 0 0 0 0 0 0 5 1 5 1 0 0 0 0 0 0 0 1 5 1 0 0 0 0 0 0 0 0 5 0 0 0 0 0 0 0 0 0
output:
1 2 3 2 4 2 1 5 1 1 2 3 2 4 2 1 5 1 1 2 3 2 4 2 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1 1 2 1 3 1 4 1 5 1
result:
ok 9 lines
Test #2:
score: -100
Wrong Answer
time: 35ms
memory: 3524kb
input:
28668 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