QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84874 | #5665. AA Country and King Dreamoon | runewrz | WA | 41ms | 3444kb | C++17 | 1.3kb | 2023-03-06 20:30:30 | 2023-03-06 20:30:34 |
Judging History
answer
#include <bits/stdc++.h>
#define fo(i, x, y) for (int i = int(x); i <= int(y); ++i)
#define fd(i, x, y) for (int i = int(x); i >= int(y); --i)
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using i64 = long long;
constexpr int inf = 1e9;
void work()
{
int n;
cin >> n;
vector<int> a(n * 2);
set<int> num;
fo(i, 1, n)
num.emplace(i);
fo(i, 1, n * 2 - 1)
cin >> a[i];
a[1] = a[n * 2 - 1] = 1;
int l = 0, r = 0;
fo(i, 1, n * 2 - 1)
{
if (!a[i])
{
if (!l) l = i;
r = i;
}
else if (num.count(a[i]))
num.erase(a[i]);
}
int lim = 0;
fd(i, n * 2 - 1, 1)
if (a[i])
lim = a[i];
else break;
vector<int> st(n + 5);
int top = 0;
fo(i, 1, n * 2 - 1)
if (a[i])
{
if (top >= 2 && a[i] == st[top - 2])
top--;
else
st[top++] = a[i];
}
else break;
fo(i, l, r)
{
if (num.size() && (top < 2 || st[top - 1] == lim || *num.begin() < st[top - 2]))
{
st[top++] = *num.begin();
a[i] = *num.begin();
num.erase(num.begin());
}
else
{
top--;
a[i] = st[top - 1];
}
}
fo(i, 1, 2 * n - 1)
cout << a[i] << " \n"[i + 1 == n * 2];
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
#ifdef LC
freopen("t.in", "r", stdin);
freopen("t.out", "w", stdout);
#endif
int T;
cin >> T;
while (T--)
work();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3340kb
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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