QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#95720#5665. AA Country and King DreamoonSGColin#WA 34ms7680kbC++201.9kb2023-04-11 16:25:272023-04-11 16:25:29

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 16:25:29]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:7680kb
  • [2023-04-11 16:25:27]
  • 提交

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], fa[N];

set<int> s;

vector<int> seq;

deque<int> tmp;

inline void work() {
	int n = rd(); 
	s.clear();
	for (int i = 1; i <= n; ++i) {
		s.insert(i); pos[i] = 0; fa[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;}
	
	for (int i = 1; i < L; ++i)	if (!fa[a[i]]) fa[a[i]] = a[i - 1];
	for (int i = 2 * n - 1; i > R; --i)	if (!fa[a[i]]) fa[a[i]] = a[i + 1];
	seq.clear(); tmp.clear();
	int nw = a[L - 1];
	while (nw != lca) {
		nw = fa[nw];
		tmp.push_back(nw);
	}
	nw = a[R + 1];
	while (nw != lca) {
		nw = fa[nw];
		seq.push_back(nw);
	}
	if (!seq.empty() && seq.back() == lca) seq.pop_back();
	reverse(seq.begin(), seq.end());
	for (auto x : seq) tmp.push_back(x);
	nw = a[L - 1];
	for (int i = L; i <= R; ++i) {
		if (s.empty()) {
			nw = a[i] = tmp.front(); tmp.pop_front();
		} else if (tmp.empty() || (*s.begin() < tmp.front())) {
			a[i] = *s.begin(); s.erase(s.begin());
			tmp.push_front(nw); nw = a[i];
		} else {
			nw = a[i] = tmp.front(); tmp.pop_front();
		}
	}

	for(int i = 1; i < 2 * n; ++i) printf("%d ", a[i]);
	puts("");
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7680kb

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: 34ms
memory: 7680kb

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 '