QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#236298 | #5665. AA Country and King Dreamoon | ItsJerr | WA | 30ms | 5476kb | C++17 | 2.8kb | 2023-11-03 20:12:10 | 2023-11-03 20:12:10 |
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;
if (*values.begin() < root) {
for (set<int>::iterator it = values.begin(); it != values.end(); ++it) {
a[p++] = *it;
if (it != values.begin()) a[p++] = *values.begin();
}
a[p++] = root;
}
else {
for (int i : values) {
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) {
if (x < nxt) 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: 1ms
memory: 5476kb
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: 30ms
memory: 5464kb
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 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