QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#784420 | #9641. Two permutations | A_programmer | 0 | 4ms | 14376kb | C++17 | 1.8kb | 2024-11-26 14:57:44 | 2024-11-26 14:57:44 |
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;
int p1[maxn], p2[maxn];
vector<int> g[maxn];
void dfs(int u)
{
sort(g[u].begin(), g[u].end());
hd1[u] = tl1[u] = u, hd2[u] = tl2[u] = u + n;
int tmph = 0, tmpt = 0;
for (int v : g[u])
{
dfs(v);
nxt[tl2[u]] = hd2[v], tl2[u] = v;
if (tmph && nxt[v]) nxt[tmpt] = nxt[v], tmpt = tl2[v];
else if (nxt[v]) tmph = nxt[v], tmpt = tl2[v];
if (nxt[hd1[v]]) nxt[tl1[u]] = nxt[hd1[v]], tl1[u] = tl1[v];
}
if (tmph) nxt[tl2[u]] = tmph, tl2[u] = tmpt;
else nxt[tl2[u]] = 0;
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]);
}
// bool c[maxn];
void work()
{
cin >> n;
for (int i = 0; i <= n; i++) g[i].clear(), hd1[i] = hd2[i] = tl1[i] = tl2[i] = 0;
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[a[i]].emplace_back(i);
for (int i = 1; i <= 2 * n; i++) nxt[i] = 0;
int t = 0;
for (int i = 1; i <= n; i++)
if (a[i] == i)
{
dfs(i);
for (int j = hd1[i], k = hd2[i]; j; j = nxt[j], k = nxt[k]) p1[++t] = (j > n ? j - n : j), p2[t] = (k > n ? k - n : k);
}
cout << "Yes\n";
for (int i = 1; i <= n; i++) cout << p1[i] << " ";
for (int i = 1; i <= n; i++) cout << p2[i] << " ";
cout << "\n";
}
int main()
{
freopen("c.in", "r", stdin);
ios::sync_with_stdio(0), cin.tie(0);
int T; cin >> T;
while (T--) work();
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11824kb
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 Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
wrong output format Expected integer, but "Yes" found
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 4ms
memory: 12740kb
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 Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
wrong output format Expected integer, but "Yes" found
Subtask #3:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 4ms
memory: 14376kb
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 Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
wrong output format Expected integer, but "Yes" found
Subtask #4:
score: 0
Wrong Answer
Test #13:
score: 0
Wrong Answer
time: 4ms
memory: 11980kb
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 Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
wrong output format Expected integer, but "Yes" found
Subtask #5:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 0ms
memory: 11652kb
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 Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
wrong output format Expected integer, but "Yes" found