QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784075 | #9641. Two permutations | A_programmer | 0 | 424ms | 19916kb | C++17 | 1.5kb | 2024-11-26 13:08:30 | 2024-11-26 13:08:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 2e5 + 5;
const int N = 4e5 + 10;
int a[maxn], hd1[maxn], tl1[maxn], hd2[maxn], tl2[maxn], nxt[N], n;
vector<int> g[maxn];
void dfs(int u)
{
sort(g[u].begin(), g[u].end());
hd1[u] = tl1[u] = u;
hd2[u] = u + n + 1, tl2[u] = u + n + 1;
for (int v : g[u])
{
dfs(v);
nxt[tl2[u]] = hd2[v], tl2[u] = tl2[v];
if (~nxt[hd1[v]]) nxt[tl1[u]] = nxt[hd1[v]], tl1[u] = tl1[v];
}
reverse(g[u].begin(), g[u].end());
for (int v : g[u]) nxt[hd1[v]] = hd1[u], hd1[u] = hd1[v];
swap(hd1[u], hd2[u]), swap(tl1[u], tl2[u]);
}
void work()
{
cin >> n;
for (int i = 0; i <= n; i++) g[i].clear(), hd1[i] = hd2[i] = tl1[i] = tl2[i] = -1;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++)
if (a[i] > i) return cout << "No\n", void();
else if (a[i] == i) g[0].emplace_back(i);
else g[a[i]].emplace_back(i);
for (int i = 0; i <= 2 * n + 1; i++) nxt[i] = -1;
dfs(0);
cout << "Yes\n";
for (int i = hd1[0]; ~i; i = nxt[i]) if (i != 0 && i != n + 1) cout << (i > n + 1 ? i - n - 1 : i) << " ";
for (int i = hd2[0]; ~i; i = nxt[i]) if (i != 0 && i != n + 1) cout << (i > n + 1 ? i - n - 1 : i) << " ";
cout << "\n";
}
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
int T; cin >> T;
while (T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 12416kb
input:
10 1 1 2 1 1 3 1 2 2 4 1 1 3 2 5 1 2 1 2 1 2 1 1 1 1 3 1 2 2 1 1 5 1 1 1 3 2
output:
Yes 1 1 Yes 2 1 1 2 Yes 1 3 2 1 2 3 Yes 2 1 4 3 1 3 4 2 Yes 3 5 1 4 2 1 2 3 5 4 Yes 2 1 1 2 Yes 1 1 Yes 1 3 2 1 2 3 Yes 1 1 Yes 2 3 1 5 4 1 5 2 4 3
result:
wrong answer Wrong Answer![4]
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 3ms
memory: 13572kb
input:
10 10 1 2 3 4 3 1 2 4 3 8 10 1 2 1 1 4 6 4 5 2 9 10 1 2 2 4 5 3 7 7 2 3 10 1 1 2 4 5 4 3 5 7 7 10 1 2 2 4 4 1 6 6 6 10 10 1 2 2 4 1 3 7 7 1 10 10 1 2 3 4 2 1 3 3 1 7 10 1 1 1 4 5 1 3 5 4 7 10 1 2 2 1 1 2 6 5 8 5 10 1 2 2 2 5 3 6 2 4 5
output:
Yes 6 1 7 2 5 9 3 8 4 10 1 2 3 4 6 7 5 9 10 8 Yes 3 4 1 8 5 7 9 2 10 6 1 2 6 3 5 7 4 8 10 9 Yes 1 3 9 2 6 10 4 5 8 7 1 2 4 5 7 6 10 3 9 8 Yes 2 1 7 3 9 10 6 4 8 5 1 4 5 3 2 9 10 7 6 8 Yes 6 1 7 8 9 3 2 5 4 10 1 2 4 10 7 8 9 6 3 5 Yes 5 9 1 3 2 6 4 8 7 10 1 2 4 7 10 5 9 6 3 8 Yes 6 9 1 5 2 7 8 ...
result:
wrong answer Wrong Answer![4]
Subtask #3:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 98ms
memory: 14036kb
input:
10 177329 1 1 2 2 1 4 1 2 3 3 2 3 4 1 2 3 3 2 2 2 2 3 4 3 1 2 4 2 4 1 4 2 2 4 1 3 3 4 1 1 1 3 2 4 3 3 2 4 2 2 4 1 1 4 3 1 4 4 4 3 1 4 1 3 2 1 2 3 2 4 2 4 4 2 1 3 2 2 2 3 3 1 4 1 3 1 2 4 1 4 2 3 4 3 1 4 4 1 2 2 3 3 4 1 4 4 3 4 3 2 1 2 4 3 1 1 4 4 4 2 3 4 3 3 3 1 4 4 1 1 2 4 4 1 3 4 4 4 2 1 2 2 1 2 3 ...
output:
Yes 2 5 7 14 25 30 35 39 40 41 52 53 56 61 63 66 75 82 84 86 89 95 98 104 111 115 116 126 129 130 134 140 143 151 152 154 155 166 173 174 175 179 180 182 190 192 206 207 209 214 221 224 226 235 239 242 243 246 252 256 259 261 274 277 278 288 289 291 292 294 295 297 300 305 307 310 312 314 320 321 32...
result:
wrong answer Wrong Answer![4]
Subtask #4:
score: 0
Wrong Answer
Test #13:
score: 15
Accepted
time: 282ms
memory: 14356kb
input:
10 199850 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...
output:
Yes 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...
result:
ok Correct!
Test #14:
score: 0
Wrong Answer
time: 314ms
memory: 16948kb
input:
10 199997 1 1 1 4 4 6 4 8 4 10 11 10 6 14 15 16 17 15 19 15 14 4 15 10 25 26 27 1 29 30 31 26 33 15 30 36 37 38 39 38 33 4 10 44 25 33 33 11 49 50 31 1 53 54 55 14 50 58 8 49 36 6 63 39 65 6 33 10 69 29 19 72 29 74 1 76 63 49 4 80 50 82 83 15 4 86 87 50 89 36 27 89 93 11 95 63 1 37 99 100 101 102 10...
output:
Yes 2 3 28 52 75 97 1928 5175 12332 20407 47532 1 5 7 9 22 42 79 85 287 4 13 62 66 376 1181 8445 10507 12078 6 59 1417 22906 54276 70223 8 12 24 43 68 161 164 7528 7785 19705 35930 118069 10 48 94 1246 1820 7584 9033 14596 177269 11 21 56 178 264 623 717 4906 38122 163038 172258 14 18 20 23 34 84 10...
result:
wrong answer Wrong Answer![4]
Subtask #5:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 424ms
memory: 19916kb
input:
10 199755 1 2 1 3 5 1 6 7 2 1 5 6 10 9 12 2 4 14 2 18 5 17 23 4 6 7 4 6 20 27 16 24 29 8 33 26 33 27 17 39 5 33 34 41 4 16 24 19 42 8 29 48 48 27 37 24 43 13 4 28 38 27 38 23 29 55 14 62 26 9 62 20 35 31 57 74 69 5 26 60 33 59 5 19 21 45 15 87 3 54 17 2 57 36 18 67 25 62 47 53 89 27 5 59 75 77 29 9 ...
output:
Yes 3 6 10 1026 1098 1218 2009 3029 4012 5130 5454 5960 9031 9337 24561 1 17 24 27 45 59 128 204 257 880 2341 3982 6662 11456 86684 90332 108289 117426 4 980 1645 1687 4833 11063 15073 40206 63951 22 29683 51590 8210 86437 113260 54442 154643 91168 94646 100511 128675 77082 107196 132398 56815 13675...
result:
wrong answer Wrong Answer![4]