QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#84874#5665. AA Country and King DreamoonrunewrzWA 41ms3444kbC++171.3kb2023-03-06 20:30:302023-03-06 20:30:34

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 20:30:34]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:3444kb
  • [2023-03-06 20:30:30]
  • 提交

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();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