QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#238886 | #5665. AA Country and King Dreamoon | ItsJerr# | WA | 33ms | 5884kb | C++17 | 2.9kb | 2023-11-04 17:49:50 | 2023-11-04 17:49:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
bool app[N];
int a[2 * N], par[N];
deque<int> get_path(int arr[], int n) {
int last = 0;
for (int i = 1; i <= n && a[i]; ++i) {
if (!par[a[i]] && a[i] != a[1]) par[a[i]] = a[i - 1];
last = a[i];
}
deque<int> ret;
while (last) {
ret.push_front(last);
last = par[last];
}
return ret;
}
void construct(int &p, int root, set<int> values) {
if (!values.size()) return;
set<int> l, r;
for (int i : values) {
if (i < root) l.insert(i);
else r.insert(i);
}
if (l.size()) {
for (int i : l) {
a[p++] = i;
if (i != *l.begin()) a[p++] = *l.begin();
}
a[p++] = root;
}
for (int i : r) {
a[p++] = i;
a[p++] = root;
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("qoj_5665.inp", "r")) {
freopen("qoj_5665.inp", "r", stdin);
freopen("qoj_5665.out", "w", stdout);
}
#ifdef LOCAL_MACHINE
if (fopen("task.inp", "r")) {
freopen("task.inp", "r", stdin);
freopen("task.out", "w", stdout);
}
#endif
int nTest; cin >> nTest;
while(nTest--) {
int n; cin >> n; n = 2 * n - 1;
for (int i = 1; i <= n; ++i) cin >> a[i];
if (n == 1) {
cout << "1\n";
continue;
}
if (!a[1] && !a[n]) a[1] = a[n] = 1;
else a[1] = a[n] = max(a[1], a[n]);
deque<int> fx = get_path(a, n);
reverse(a + 1, a + n + 1);
deque<int> fy = get_path(a, n);
reverse(a + 1, a + n + 1);
while (fx.size() > 1 && fy.size() > 1 && fx[1] == fy[1]) {
fx.pop_front();
fy.pop_front();
}
fy.pop_front();
reverse(fx.begin(), fx.end());
for (int i : fy) fx.push_back(i);
set<int> out;
for (int i = 1; i <= n; ++i) app[a[i]] = 1;
for (int i = 1; i <= n / 2 + 1; ++i) if (!app[i]) out.insert(i);
int L = 1;
while (a[L] && L <= n) ++L;
for (int i = 0; i + 1 < (int) fx.size(); ++i) {
int cur = fx[i], nxt = fx[i + 1];
set<int> proc;
for (int x : out) {
int lim = nxt;
if (proc.size() && *proc.begin() < cur) lim = cur;
if (x < lim) proc.insert(x);
else break;
}
for (int i : proc) out.erase(i);
if (proc.size()) construct(L, cur, proc);
a[L++] = nxt;
}
construct(L, fx.back(), out);
for (int i = 1; i <= n; ++i) cout << a[i] << " ";
cout << "\n";
for (int i = 1; i <= n / 2 + 1; ++i) app[i] = par[i] = 0;
}
}
// ඞඞඞඞඞ you sus
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 33ms
memory: 5884kb
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 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