QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#84327 | #5665. AA Country and King Dreamoon | HOLIC | WA | 91ms | 3376kb | C++20 | 2.4kb | 2023-03-06 10:45:11 | 2023-03-06 10:45:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 1009;
int n, a[N], vis[N], fa[N], dep[N];
void work() {
cin >> n;
for(int i = 1; i < 2 * n; i ++) cin >> a[i];
a[1] = a[2 * n - 1] = 1;
int l = 2 * n, r = 0;
for(int i = 1; i < 2 * n; i ++) {
if(a[i] == 0) {
l = min(l, i);
r = max(r, i);
}
}
for(int i = 1; i <= n; i ++) dep[i] = vis[i] = fa[i] = 0;
int now = 0;
for(int i = 1; i < l; i ++) {
if(vis[a[i]]) now = a[i];
else fa[a[i]] = now, dep[a[i]] = dep[now] + 1, now = a[i];
vis[a[i]] = 1;
}
set<int> s;
for(int i = 1; i <= n; i ++) s.insert(i), vis[i] = 0;
int Now = 0;
for(int i = 2 * n - 1; i > r; i --) {
if(vis[a[i]]) Now = a[i];
else fa[a[i]] = Now, dep[a[i]] = dep[Now] + 1, Now = a[i];
vis[a[i]] = 1;
}
for(int i = 1; i <= n; i ++)
s.erase(a[i]);
int num = r - l + 1;
vector<int> a1, a2;
int x = now, X = Now;
//cout << x << " " << X << " " << dep[x] << " " << dep[X] << endl;
while(x != X) {
if(dep[x] >= dep[X]) {
x = fa[x];
if(x != X) a2.push_back(x);
}
else {
X = fa[X];
if(x != X) a2.push_back(X);
}
//cout << x << " " << X << endl;
}
if(now != Now)a2.push_back(Now);
reverse(a2.begin(), a2.end());
for(auto v : a2) a1.push_back(v);
//for(auto v : a1) cout << v << " ";
//cout << endl;
reverse(a1.begin(), a1.end());
if(l > r) {
for(int i = 1; i < 2 * n; i ++) cout << a[i] << " ";
cout << endl;
return;
}
for(int i = 1; i < l; i ++) cout << a[i] << " ";
// cout << l << " " <<r << endl;
for(int i = l; i <= r; i ++) {
if(!s.empty() && (a1.empty() || *s.begin() < a1.back())) {
a1.push_back(now);
now = *s.begin();
s.erase(s.begin());
cout << now << " ";
} else {
cout << a1.back() << " ";
now = a1.back();
a1.pop_back();
}
}
for(int i = r + 1; i < 2 * n; i ++) cout << a[i] << " ";
cout << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int Case;
cin >> Case;
while(Case --) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3324kb
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: 91ms
memory: 3376kb
input:
28668 2 0 2 1 2 0 0 1 2 0 0 0 2 1 0 1 2 1 0 0 2 1 2 0 3 0 2 1 3 1 3 0 0 1 3 1 3 0 0 0 3 1 3 0 0 0 0 1 3 0 0 0 0 0 3 1 0 1 3 1 3 1 0 0 3 1 3 1 0 0 0 1 3 1 0 0 0 0 3 1 2 0 3 1 3 1 2 0 0 1 3 1 2 0 0 0 3 1 2 1 0 1 3 1 2 1 0 0 3 1 2 1 3 0 3 0 2 3 2 1 3 0 0 3 2 1 3 0 0 0 2 1 3 1 0 3 2 1 3 1 0 0 2 1 3 1 2 ...
output:
1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 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