QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95691 | #5665. AA Country and King Dreamoon | SGColin# | WA | 37ms | 5672kb | C++14 | 1.2kb | 2023-04-11 13:49:51 | 2023-04-11 13:49:53 |
Judging History
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], posl[N];
set<int> s;
inline void work() {
int n = rd();
s.clear();
for (int i = 1; i <= n; ++i) {
s.insert(i); posl[i] = 0;
}
int L = 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]) {L = i; break;}
if (!L) {
for (int i = 1; i < 2 * n; ++i) printf("%d ", a[i]);
puts(""); return;
}
int R = L;
while (a[R] == 0) ++R; --R;
int x = 0, posr = 0;
for (int i = 1; i < L; ++i) posl[a[i]] = i;
for (int i = R + 1; i < 2 * n; ++i)
if (posl[a[i]]) {x = a[i]; posr = i; break;}
for (int i = L - 2; i >= posl[x]; --i) a[L++] = a[i];
for (int i = R + 2; i <= posr; ++i) a[R--] = a[i];
for (int i = L; i <= R; ++i) {
a[i] = *s.begin(); s.erase(s.begin());
a[++i] = x;
}
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: 3ms
memory: 5672kb
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 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