QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#784426#9641. Two permutationsA_programmer40 426ms21624kbC++171.8kb2024-11-26 14:58:222024-11-26 14:58:26

Judging History

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

  • [2024-11-26 14:58:26]
  • 评测
  • 测评结果:40
  • 用时:426ms
  • 内存:21624kb
  • [2024-11-26 14:58:22]
  • 提交

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()
{
    ios::sync_with_stdio(0), cin.tie(0);

    int T; cin >> T;
    while (T--) work();
    return 0;
}

詳細信息

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 0ms
memory: 15324kb

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
1 2 2 1 
Yes
1 2 3 1 3 2 
Yes
1 4 2 3 2 1 4 3 
Yes
1 3 5 2 4 3 5 1 4 2 
Yes
1 2 2 1 
Yes
1 1 
Yes
1 2 3 1 3 2 
Yes
1 1 
Yes
1 5 2 4 3 2 3 1 5 4 

result:

ok Correct!

Test #2:

score: 10
Accepted
time: 3ms
memory: 14636kb

input:

10
4
1 2 3 3
1
1
5
1 2 1 4 2
1
1
3
1 1 1
5
1 1 1 1 1
3
1 2 1
5
1 1 2 3 4
5
1 1 1 3 2
5
1 1 3 1 5

output:

Yes
1 2 3 4 1 2 4 3 
Yes
1 1 
Yes
1 3 2 5 4 3 1 5 2 4 
Yes
1 1 
Yes
1 2 3 2 3 1 
Yes
1 2 3 4 5 2 3 4 5 1 
Yes
1 3 2 3 1 2 
Yes
1 3 2 5 4 2 1 4 3 5 
Yes
1 5 2 4 3 2 3 1 5 4 
Yes
1 2 4 3 5 2 4 1 3 5 

result:

ok Correct!

Test #3:

score: 10
Accepted
time: 0ms
memory: 14524kb

input:

10
5
1 2 3 4 5
5
1 1 2 3 4
5
1 2 2 3 4
5
1 1 3 2 5
5
1 1 1 1 1
5
1 2 3 4 4
5
1 2 2 2 2
5
1 1 1 2 3
5
1 2 1 2 1
5
1 2 1 2 2

output:

Yes
1 2 3 4 5 1 2 3 4 5 
Yes
1 3 2 5 4 2 1 4 3 5 
Yes
1 2 4 3 5 1 3 2 5 4 
Yes
1 4 2 3 5 2 1 4 3 5 
Yes
1 2 3 4 5 2 3 4 5 1 
Yes
1 2 3 4 5 1 2 3 5 4 
Yes
1 2 3 4 5 1 3 4 5 2 
Yes
1 4 2 5 3 2 3 1 4 5 
Yes
1 3 5 2 4 3 5 1 4 2 
Yes
1 3 2 4 5 3 1 4 5 2 

result:

ok Correct!

Subtask #2:

score: 0
Wrong Answer

Test #4:

score: 10
Accepted
time: 3ms
memory: 13496kb

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
1 6 2 7 3 5 9 4 10 8 6 1 7 2 5 9 3 8 4 10 
Yes
1 3 5 7 4 8 2 10 9 6 3 4 1 8 5 7 9 2 10 6 
Yes
1 2 6 10 3 9 4 5 7 8 1 3 9 2 6 10 4 5 8 7 
Yes
1 3 2 9 10 7 4 6 5 8 2 1 7 3 9 10 6 4 8 5 
Yes
1 7 8 9 6 2 3 4 5 10 6 1 7 8 9 3 2 5 4 10 
Yes
1 5 9 2 6 3 4 7 8 10 5 9 1 3 2 6 4 8 7 10 
Yes
1 6 9 2 5 3 10...

result:

ok Correct!

Test #5:

score: 10
Accepted
time: 2ms
memory: 14028kb

input:

10
10
1 1 3 1 1 1 2 3 5 7
10
1 2 2 1 4 5 6 7 9 8
10
1 2 2 1 5 4 2 3 6 8
10
1 1 1 4 5 3 1 2 2 3
10
1 1 2 4 5 2 6 2 6 3
10
1 2 3 3 5 4 6 1 9 6
10
1 1 1 4 1 4 1 2 8 10
10
1 2 2 2 1 3 1 1 5 8
10
1 1 3 1 5 3 2 5 6 5
10
1 2 3 4 1 5 7 8 4 2

output:

Yes
1 7 2 4 9 5 6 10 3 8 2 4 5 6 1 10 7 9 8 3 
Yes
1 5 4 7 6 10 8 2 3 9 4 1 6 5 8 7 10 3 2 9 
Yes
1 6 4 9 2 8 3 7 10 5 4 1 9 6 3 7 2 10 8 5 
Yes
1 8 9 2 6 10 3 7 4 5 2 3 7 1 8 9 6 10 4 5 
Yes
1 3 6 8 2 10 7 9 4 5 2 1 10 3 7 9 6 8 4 5 
Yes
1 8 2 3 6 4 7 10 5 9 8 1 2 4 3 7 10 6 5 9 
Yes
1 8 2 3 5 7 9 ...

result:

ok Correct!

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 14504kb

input:

10
10
1 1 1 3 5 4 1 2 8 9
10
1 2 2 1 2 2 5 4 5 1
10
1 1 1 1 1 2 5 2 1 10
10
1 2 2 3 2 1 3 4 7 4
9
1 1 4 3 3 5 5 4 5
9
1 1 2 2 5 4 6 3 3
9
1 2 1 4 3 5 2 5 3
10
1 2 2 4 2 5 5 3 1 9
9
1 2 3 2 4 5 6 8 9
10
1 1 1 1 4 6 4 5 7 10

output:

Yes
1 8 2 4 3 7 10 9 6 5 2 3 7 1 9 8 10 6 4 5 
Yes
1 8 4 10 2 3 7 9 5 6 4 10 1 8 3 5 6 2 7 9 
Yes
1 6 8 2 3 4 7 5 9 10 2 3 4 5 9 1 6 8 7 10 
Yes
1 6 2 4 7 3 5 8 10 9 6 1 3 5 2 8 10 4 9 7 
No
Yes
1 3 4 2 8 9 7 6 5 2 1 8 9 3 6 4 7 5 
Yes
1 5 9 3 6 8 2 7 4 3 1 6 8 5 9 7 2 4 
Yes
1 10 9 2 8 3 6 7 5 4 9 ...

result:

wrong answer Wrong Answer![4]

Subtask #3:

score: 15
Accepted

Test #7:

score: 15
Accepted
time: 110ms
memory: 15652kb

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
1 3 4 8 11 15 18 19 20 21 26 28 32 33 43 47 49 50 65 67 69 71 74 77 78 79 87 91 99 100 110 112 120 131 139 141 142 144 147 157 159 162 164 167 171 172 176 178 185 186 194 195 196 200 213 216 219 220 222 223 225 227 229 230 232 236 241 245 247 250 251 253 255 257 260 269 271 279 280 283 285 286 2...

result:

ok Correct!

Test #8:

score: 15
Accepted
time: 126ms
memory: 15708kb

input:

10
42861
1 2 1 2 3 1 2 2 1 1 3 4 3 1 2 3 2 2 3 2 3 4 2 2 2 4 2 3 1 2 1 4 4 2 4 3 1 1 4 3 1 1 4 1 1 4 3 3 1 3 3 3 2 4 4 1 3 2 1 1 1 1 1 1 4 3 1 1 2 4 1 1 2 4 2 3 4 4 4 2 4 3 3 3 2 1 3 4 4 3 1 3 4 4 4 1 4 4 1 3 2 4 4 3 3 4 3 3 4 3 1 4 2 1 2 3 2 4 3 4 1 2 3 4 2 4 1 3 4 1 1 1 4 3 4 2 1 4 3 1 3 3 2 1 1 4...

output:

Yes
1 5 11 13 16 19 21 28 36 40 47 48 50 51 52 57 66 76 82 83 84 87 90 92 100 104 105 107 108 110 116 119 123 128 134 139 141 142 147 150 151 157 161 163 164 176 177 179 180 188 203 204 206 214 216 219 221 223 225 229 234 237 239 244 246 259 261 263 265 266 268 269 273 277 278 279 284 286 290 294 29...

result:

ok Correct!

Test #9:

score: 15
Accepted
time: 105ms
memory: 15764kb

input:

10
45364
1 1 1 1 1 1 1 2 2 2 2 1 2 4 3 3 1 4 1 3 2 2 3 1 2 2 3 2 3 3 3 2 3 3 2 3 2 1 1 3 4 2 2 4 4 3 1 2 4 1 3 4 4 1 3 4 1 4 3 2 1 2 3 3 4 4 1 3 3 3 2 3 4 4 2 1 2 1 2 1 1 2 2 2 3 1 3 3 1 4 1 3 1 2 3 4 2 2 3 3 1 3 3 4 4 4 4 1 1 4 4 1 4 2 2 1 1 4 3 3 4 3 4 4 4 4 4 1 4 4 1 4 3 1 3 1 3 3 4 1 1 2 1 2 1 3...

output:

Yes
1 8 9 10 11 13 21 22 25 26 28 32 35 37 42 43 48 60 62 71 75 77 79 82 83 84 94 97 98 114 115 142 144 157 160 165 166 167 172 188 189 199 202 206 207 215 217 223 229 231 234 239 240 244 246 249 250 255 264 266 273 283 290 294 296 299 302 305 308 315 316 319 321 324 330 336 339 340 341 342 347 349 ...

result:

ok Correct!

Test #10:

score: 15
Accepted
time: 112ms
memory: 15528kb

input:

10
60502
1 1 3 2 4 3 2 4 4 1 2 2 3 3 4 3 3 4 3 1 3 4 1 2 1 1 2 1 4 2 2 2 4 4 4 3 3 1 4 1 3 4 4 4 4 2 1 3 1 2 4 4 2 1 4 4 1 2 3 3 1 2 2 4 1 3 3 1 4 1 2 2 4 1 1 4 2 1 3 3 4 4 4 4 2 2 2 2 4 4 4 3 4 3 2 4 4 4 1 4 2 3 2 3 2 3 2 1 3 2 4 2 1 1 1 3 2 3 2 2 1 2 1 4 2 2 4 4 2 3 2 4 2 1 4 2 3 2 1 1 1 1 3 2 2 3...

output:

Yes
1 4 7 11 12 24 27 30 31 32 46 50 53 58 62 63 71 72 77 85 86 87 88 95 101 103 105 107 110 112 117 119 120 122 125 126 129 131 133 136 138 144 145 149 150 157 167 169 175 181 185 190 200 211 213 217 224 229 242 247 248 249 252 255 256 257 262 265 266 270 279 282 286 290 295 298 306 307 310 314 315...

result:

ok Correct!

Test #11:

score: 15
Accepted
time: 114ms
memory: 15896kb

input:

10
192651
1 2 4 1 3 2 3 1 1 4 2 2 2 2 1 3 2 3 1 1 1 1 2 4 3 4 2 2 1 2 3 4 4 3 1 3 1 4 1 3 4 1 4 2 4 1 2 1 2 2 4 2 4 4 1 4 3 2 2 1 1 3 1 3 2 2 3 1 4 3 4 4 3 1 3 2 2 2 3 3 3 1 1 2 3 3 2 3 2 3 3 4 2 4 1 1 2 1 4 4 1 1 1 1 1 2 2 2 2 4 3 3 4 4 2 3 2 1 2 3 2 2 1 4 3 4 1 4 2 4 4 4 2 1 1 3 2 1 2 1 3 1 2 3 1 ...

output:

No
Yes
1 4 7 13 14 24 26 31 33 37 38 39 41 43 48 53 55 63 64 65 67 74 77 79 80 88 90 91 92 93 100 103 105 106 113 114 123 125 127 135 136 137 140 141 144 152 155 156 158 159 163 166 168 169 170 173 176 179 184 186 193 198 201 207 208 209 212 217 220 224 225 232 233 234 239 240 250 261 266 268 273 27...

result:

ok Correct!

Test #12:

score: 15
Accepted
time: 110ms
memory: 15548kb

input:

10
96064
1 1 1 1 4 4 1 4 1 1 2 1 3 4 3 2 2 2 1 1 1 2 1 1 3 4 1 2 2 3 2 2 3 4 4 3 3 3 4 3 2 3 3 4 3 4 3 4 2 3 2 2 3 4 1 1 1 2 3 2 3 3 4 1 4 4 3 1 2 3 3 3 3 2 4 4 2 2 3 4 4 1 4 1 1 2 1 4 2 3 3 2 4 2 1 4 3 4 1 4 4 2 1 3 1 2 4 2 2 4 3 3 4 4 4 3 3 4 1 3 2 1 2 1 2 1 2 1 2 4 3 4 1 4 4 4 2 1 2 1 4 3 3 4 2 1...

output:

Yes
1 11 16 17 18 22 28 29 31 32 41 49 51 52 58 60 69 74 77 78 86 89 92 94 102 106 108 109 121 123 125 127 129 137 139 145 152 167 168 172 180 181 189 190 191 194 195 200 202 205 218 222 230 232 237 248 251 253 255 260 262 263 268 270 273 284 285 287 289 291 292 293 297 301 303 307 312 314 315 316 3...

result:

ok Correct!

Subtask #4:

score: 15
Accepted

Test #13:

score: 15
Accepted
time: 271ms
memory: 15360kb

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: 15
Accepted
time: 295ms
memory: 18204kb

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
1 2 3 28 52 75 97 1928 5175 12332 20407 47532 4 5 7 9 22 42 79 85 287 6 13 62 66 376 1181 8445 10507 12078 8 59 1417 22906 54276 70223 10 12 24 43 68 161 164 7528 7785 19705 35930 118069 11 48 94 1246 1820 7584 9033 14596 177269 14 21 56 178 264 623 717 4906 38122 163038 172258 15 18 20 23 34 84...

result:

ok Correct!

Test #15:

score: 15
Accepted
time: 309ms
memory: 19052kb

input:

10
199730
1 2 2 2 1 2 2 1 2 10 2 12 13 10 15 16 17 13 19 20 1 13 16 24 19 2 27 28 29 17 28 12 1 16 28 1 17 13 24 17 41 42 24 17 41 28 47 2 2 2 51 52 51 15 42 56 57 42 59 20 51 62 47 64 47 66 42 12 69 70 69 15 51 74 10 47 77 78 13 69 81 82 83 84 64 2 87 28 10 90 91 10 13 74 70 96 97 12 99 17 15 17 87...

output:

Yes
1 5 8 21 33 36 107 206 230 233 239 257 338 908 982 1546 4261 5880 6829 13759 14036 18578 24293 29360 102979 119054 2 3 4 6 7 9 11 26 48 49 50 86 179 181 187 219 267 369 420 580 730 3275 6356 7904 17885 139917 143842 10 14 75 89 92 500 1223 1400 1567 4099 7880 8250 16239 18222 55120 57083 78538 8...

result:

ok Correct!

Test #16:

score: 15
Accepted
time: 315ms
memory: 18800kb

input:

10
199782
1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 2 1 1 1 1 2 2 1 2 1 1 2 1 1 2 2 1 33 33 33 33 1 2 1 1 2 2 1 2 2 33 2 1 1 1 33 33 2 33 2 1 2 2 1 1 2 1 1 33 2 2 1 33 2 1 33 1 1 2 2 33 2 33 2 1 33 33 33 2 2 1 1 1 1 1 33 2 2 2 2 33 1 1 2 33 1 33 1 1 1 2 2 2 33 33 33 2 2 1 33 2 33 2 2 2 33 33 1 1 33 1 33 2 1 2 3...

output:

Yes
1 5 6 7 8 9 17 18 19 20 23 25 26 28 29 32 37 39 40 43 48 49 50 56 59 60 62 63 67 70 72 73 80 86 87 88 89 90 97 98 101 103 104 105 114 123 124 126 129 136 137 138 139 140 141 142 148 150 151 153 155 156 160 166 172 177 178 180 184 192 193 196 197 201 202 203 206 219 220 224 226 227 230 233 237 24...

result:

ok Correct!

Test #17:

score: 15
Accepted
time: 265ms
memory: 16480kb

input:

10
199768
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

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 #18:

score: 15
Accepted
time: 91ms
memory: 15276kb

input:

10
199897
1 133473 137888 154846 104937 137888 3569 104774 144338 186307 16043 175982 174471 97731 56127 91564 38890 40649 89585 22112 91564 169703 102594 111754 96581 132350 39595 142435 3652 102405 58841 71649 89585 104964 111754 27732 141427 45005 177850 292 102734 71015 113628 177036 16043 30227...

output:

No
No
No
No
No
No
No
No
No
No

result:

ok Correct!

Subtask #5:

score: 0
Wrong Answer

Test #19:

score: 0
Wrong Answer
time: 426ms
memory: 21624kb

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
1 4 89 552 13736 18205 44148 3 7 12 25 28 720 7551 56126 150925 158751 6 13 681 746 784 1532 3944 4960 15809 10 1169 3155 3200 4224 8857 57368 1026 5658 11812 1098 4362 7480 9618 1218 37182 40466 88473 2009 5843 18851 37384 54646 89062 138056 3029 4773 5108 36011 47124 154294 4012 7293 30126 513...

result:

wrong answer Wrong Answer![4]