QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#95700#5665. AA Country and King DreamoonSGColin#WA 37ms5640kbC++201.9kb2023-04-11 14:40:192023-04-11 14:40:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-11 14:40:22]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:5640kb
  • [2023-04-11 14:40:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

inline int rd() {
	int x = 0;
	bool f = 0;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) f |= (c == '-');
	for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return f ? -x : x;
}

#define N 1000007

int a[N], pos[N];

set<int> s;

vector<int> seq;

inline void work() {
	int n = rd(); 
	s.clear();
	for (int i = 1; i <= n; ++i) {
		s.insert(i); pos[i] = 0;
	}
	int L = 0, R = 0;
	for (int i = 1; i < 2 * n; ++i) a[i] = rd();
	a[1] = a[2 * n - 1] = 1;
	for (int i = 1; i < 2 * n; ++i) s.erase(a[i]);
	for (int i = 2; i < 2 * n; ++i) if (!a[i]) {if (!L) L = i; R = i;}
	if (!L) {
		for (int i = 1; i < 2 * n; ++i) printf("%d ", a[i]);
		puts(""); return;
	}

	int lca = 0, posr = 0, posl = 0;
	for (int i = 1; i < L; ++i) pos[a[i]] = i;
	for (int i = R + 1; i < 2 * n; ++i)
		if (pos[a[i]]) {lca = a[i]; posl = pos[a[i]]; posr = i; break;}

	seq.clear();
	seq.push_back(lca);
	for (int i = L - 1; i; --i) pos[a[i]] = i;
	for (int i = posl; i < L; ++i) {
		if (pos[a[i]] < i) {
			while (seq.back() != a[i]) seq.pop_back();
		} else if (seq.back() != a[i]) seq.push_back(a[i]);
	}
	seq.pop_back();
	reverse(seq.begin(), seq.end());
	//puts("???");
	//for (auto x : seq) printf("%d ", x); puts("");
	for (auto x : seq) a[L++] = x;
	
	seq.clear();
	seq.push_back(lca);
	for (int i = R + 1; i < 2 * n; ++i) pos[a[i]] = i;
	for (int i = posr; i > R; --i) {
		if (pos[a[i]] > i) {
			while (seq.back() != a[i]) seq.pop_back();
		} else if (seq.back() != a[i]) seq.push_back(a[i]);
	}
	seq.pop_back();
	reverse(seq.begin(), seq.end());
	//puts("???");
	//for (auto x : seq) printf("%d ", x); puts("");
	for (auto x : seq) a[R--] = x;

	for (int i = L; i <= R; ++i) {
		a[i] = *s.begin(); s.erase(s.begin());
		a[++i] = lca;
	}
	for(int i = 1; i < 2 * n; ++i) printf("%d ", a[i]);
	puts("");
}

int main() {
	for (int t = rd(); t; --t) work();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5640kb

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: 37ms
memory: 5580kb

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
3
0 0 3 2 1
3
0 0 0 2 1
3
1 0 3 2 1
3
1 0 0 2 1
3
1 2 ...

output:

1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 3 2 1 
1 2 3 2 1 
1 3 1 2 1 
1 2 3 2 1 
1 3 1 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3...

result:

wrong answer 24th lines differ - expected: '1 2 3 2 1', found: '1 3 1 2 1 '