QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184497 | #5665. AA Country and King Dreamoon | ucup-team1508# | WA | 26ms | 3560kb | C++14 | 2.1kb | 2023-09-20 20:07:54 | 2023-09-20 20:07:55 |
Judging History
answer
#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define Fd(i, a, b) for(int i = a; i >= b; i --)
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 3e5 + 10;
int n, a[N], fa[N], vst[N];
void sol() {
cin >> n;
F(i, 1, 2 * n - 1) cin >> a[i];
a[1] = a[2 * n - 1] = 1;
F(i, 1, n) fa[i] = vst[i] = 0;
vst[1] = 3;
int pos = 0;
F(i, 2, 2 * n - 1) {
if(a[i] == 0) {
pos = i;
break;
}
if(! vst[a[i]]) vst[a[i]] = 1, fa[a[i]] = a[i - 1];
else if(fa[a[i - 1]] == a[i]) vst[a[i - 1]] = 3;
}
Fd(i, 2 * n - 2, 2) {
if(a[i] == 0) break;
if(vst[a[i]] == 0) vst[a[i]] = 2, fa[a[i]] = a[i + 1];
if(vst[a[i]] == 2) {
if(fa[a[i]] == a[i - 1]) vst[a[i]] = 3;
}
if(vst[a[i]] == 1) {
if(fa[a[i]] == a[i + 1]) vst[a[i]] = 3;
}
}
// F(i, 1, n) cout << fa[i] << " \n" [i == n];
// F(i, 1, n) cout << vst[i] << " \n" [i == n];
priority_queue<int, vector<int>, greater<int> > q;
F(i, 1, n) if(! vst[i] || vst[i] == 2) q.push(i);
F(i, pos, 2 * n - 1) {
if(a[i]) break;
int x = 0, y = fa[a[i - 1]];
while(q.size() && (vst[q.top()] == 1 || vst[q.top()] == 3)) q.pop();
if(q.size()) x = q.top();
if(x && (vst[a[i - 1]] == 2 || vst[a[i - 1]] == 3 || x < y)) {
a[i] = q.top();
fa[a[i]] = a[i - 1];
if(vst[a[i]] == 2) vst[a[i]] = 3;
else vst[a[i]] = 1;
q.pop();
continue;
}
vst[a[i - 1]] = 3;
a[i] = fa[a[i - 1]];
}
F(i, 1, 2 * n - 1) cout << a[i] << " \n" [i == 2 * n - 1];
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t; cin >> t;
while(t --) sol();
}
/*
1
5
1 0 0 0 3 4 3 2 1
*/
/*
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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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: 26ms
memory: 3528kb
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 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