QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#562843 | #1817. AND Permutation | arnold518# | AC ✓ | 1059ms | 89456kb | C++17 | 1.9kb | 2024-09-13 21:29:49 | 2024-09-13 21:29:51 |
Judging History
answer
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
vector<pll> f(vector<ll> A, vector<ll> B, int k)
{
assert(A.size() == B.size());
if(A.size() == 0) return vector<pll>();
if(A.size() == 1) return vector<pll>{{A[0], B[0]}};
vector<pll> V, W;
vector<ll> C, D, E, F;
for(auto i : A)
{
if(i >> k & 1) V.push_back({ (i >> (k + 1)), i });
else C.push_back(i);
}
for(auto i : B)
{
if(i >> k & 1) W.push_back({ (i >> (k + 1)), i });
else D.push_back(i);
}
V.push_back({1ll << 61, 0});
W.push_back({1ll << 61, 0});
sort(V.begin(), V.end());
sort(W.begin(), W.end());
auto X = f(C, D, k + 1);
vector<pll> ret;
for(auto [x, y] : X)
{
auto [i, _x] = *lower_bound(V.begin(), V.end(), pll{x >> (k + 1), -1});
auto [j, _y] = *lower_bound(W.begin(), W.end(), pll{y >> (k + 1), -1});
bool f1 = (i == (x >> (k + 1)));
bool f2 = (j == (y >> (k + 1)));
if(!f1 && !f2) ret.push_back({x, y});
else if(!f1 && f2)
{
ret.push_back({x, _y});
F.push_back(y);
}
else if(f1 && !f2)
{
ret.push_back({_x, y});
E.push_back(x);
}
else
{
ret.push_back({x, _y});
E.push_back(_x);
F.push_back(y);
}
}
auto Y = f(E, F, k + 1);
for(auto [x, y] : Y) ret.push_back({x, y});
return ret;
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
int n; cin >> n;
vector<ll> A(n); for(auto &i : A) cin >> i;
auto B = f(A, A, 0);
sort(B.begin(), B.end());
for(auto i : A) cout << lower_bound(B.begin(), B.end(), pll{i, -1})->ss << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
6 0 1 4 5 2 6
output:
4 6 0 2 5 1
result:
ok OK!
Test #2:
score: 0
Accepted
time: 1ms
memory: 3812kb
input:
272 315 138 126 6 394 297 44 273 84 200 9 197 396 133 16 46 65 87 86 336 316 174 140 162 250 306 52 188 57 36 63 192 320 388 10 156 15 208 38 32 31 228 30 305 234 384 220 142 72 27 337 110 94 317 304 242 398 209 5 323 29 284 301 309 244 230 261 61 254 266 194 296 275 313 80 206 214 88 308 18 288 106...
output:
196 53 384 280 116 214 83 238 128 311 182 314 114 58 270 81 62 160 136 132 195 337 51 21 261 4 258 323 70 274 64 319 148 122 308 35 176 303 153 278 96 283 288 206 277 126 291 49 151 100 174 129 416 194 134 269 112 302 186 188 98 2 210 202 267 281 250 66 257 52 317 215 236 198 46 305 297 422 130 268 ...
result:
ok OK!
Test #3:
score: 0
Accepted
time: 9ms
memory: 4540kb
input:
5134 36416 73248 85220 2072 16524 36385 101507 91137 17604 22 640 70530 66850 107792 81952 163 84260 46246 45090 101411 18824 66360 116881 400 50338 109824 17508 122881 98691 99843 36481 1696 102658 27008 2566 4 32900 103171 1153 104706 69923 82280 19616 66849 17540 36870 8352 117777 82156 6785 6780...
output:
90497 33152 41496 1060 109569 70018 24832 35008 67880 2280 105760 35857 39568 23169 1476 68868 1160 84296 85452 720 66656 60545 9312 73251 4169 21137 67976 3150 27648 6560 69922 104707 3744 99331 83176 69864 3587 1232 61472 237 34000 3203 65609 39552 39713 66465 54278 8576 42257 99616 17668 71264 21...
result:
ok OK!
Test #4:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
15 10 0 11 13 2 14 4 1 5 6 8 12 3 7 9
output:
5 0 4 2 13 1 11 14 10 9 7 3 12 8 6
result:
ok OK!
Test #5:
score: 0
Accepted
time: 5ms
memory: 4248kb
input:
3237 9776 12036 8229 2100 10676 17349 26144 2690 30256 3088 27328 31796 3344 54 3637 16908 17030 31749 8593 153 20020 2305 24980 17413 1155 16524 1068 16576 2881 1139 10416 1924 17284 1042 16969 1066 28084 24608 29220 25125 19744 26117 128 28724 4760 17792 27008 17696 4372 6784 19157 8577 405 19072 ...
output:
18629 16408 20112 25280 22017 15408 2257 24657 2501 29220 272 961 25102 1097 28672 10369 10248 528 18980 1122 8385 25268 2592 14896 120 10753 81 11028 24724 27276 17221 30769 10289 76 11444 27349 4680 2772 3088 3216 8789 2296 1144 3584 26916 14901 59 10837 27296 1107 9504 18996 27168 8205 20692 8533...
result:
ok OK!
Test #6:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
32 21 10 13 29 15 30 14 0 26 19 18 2 8 25 5 23 17 12 24 3 4 22 20 27 6 9 1 28 7 16 11 31
output:
10 21 18 2 16 1 17 31 5 12 13 29 23 6 26 8 14 19 7 28 27 9 11 4 25 22 30 3 24 15 20 0
result:
ok OK!
Test #7:
score: 0
Accepted
time: 1ms
memory: 3688kb
input:
286 304 63 445 257 143 170 407 68 55 44 256 53 176 310 4 436 356 33 6 442 160 38 314 273 296 420 299 173 64 408 0 401 169 423 40 284 135 187 358 397 301 70 260 393 190 174 36 428 65 183 421 21 390 58 28 73 288 434 403 104 10 405 443 168 46 43 171 47 398 311 185 279 413 15 277 23 19 20 42 261 278 139...
output:
143 384 66 190 304 277 104 443 392 403 63 394 263 137 315 1 155 30 313 4 271 281 133 174 151 9 148 274 447 34 319 42 278 88 23 163 312 324 153 48 146 441 59 50 256 273 283 17 446 264 24 426 121 389 419 438 31 5 44 407 437 40 68 279 401 404 276 400 113 136 326 168 98 432 170 424 428 427 405 186 169 3...
result:
ok OK!
Test #8:
score: 0
Accepted
time: 1ms
memory: 3688kb
input:
260 261 790 778 536 273 7 28 19 840 12 3 527 75 4 599 795 336 543 793 82 850 286 852 2 848 539 841 587 847 326 535 515 519 837 86 78 322 271 525 80 785 22 596 523 794 95 81 339 70 798 590 67 333 69 834 284 21 540 30 72 789 581 514 8 26 27 11 1024 594 770 257 348 279 861 331 73 600 264 277 577 6 345 ...
output:
602 73 85 327 590 856 835 844 7 851 860 336 788 859 264 68 527 320 70 781 13 577 9 861 11 324 6 276 16 537 328 348 344 26 777 785 541 592 338 783 78 841 267 340 69 768 782 524 793 65 273 796 530 794 29 579 842 323 833 791 74 282 349 343 837 836 852 863 269 93 606 515 584 0 532 790 263 599 586 286 85...
result:
ok OK!
Test #9:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
128 240 194 178 243 2 131 163 32 112 225 153 129 97 82 25 158 140 144 134 66 69 65 98 24 13 26 192 157 160 3 49 211 196 6 133 14 33 5 12 139 99 176 28 179 83 138 11 150 19 155 224 137 208 15 4 154 113 143 147 135 18 81 34 149 73 136 23 76 209 30 197 146 27 17 80 48 227 145 168 152 68 0 50 1 51 29 20...
output:
15 49 77 12 133 20 80 149 143 30 66 6 158 160 194 97 115 7 25 177 154 150 157 195 242 129 27 98 21 148 192 40 35 153 10 241 210 138 243 16 156 65 227 76 168 17 144 73 196 0 31 2 34 240 139 1 142 112 68 24 137 170 197 8 146 3 200 179 42 225 26 9 128 132 162 193 28 4 83 67 163 151 205 134 204 226 161 ...
result:
ok OK!
Test #10:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
24 2 12 28 5 26 3 24 10 8 7 22 17 1 6 16 20 19 0 18 11 4 9 25 27
output:
0 19 3 26 5 28 7 16 18 24 9 10 2 25 1 11 12 17 8 20 27 22 6 4
result:
ok OK!
Test #11:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
1572 2144 58 3077 672 2376 2112 3978 1879 1170 557 2817 851 3975 2346 1814 1294 24 2602 1610 3457 606 1875 2818 2629 864 2156 1350 178 30 674 1547 2668 2948 1864 2432 2178 1310 176 2317 658 1057 587 2152 256 2927 1069 1282 1682 440 2208 2096 2850 1213 3076 3599 2607 1574 849 657 1188 578 676 1161 11...
output:
1159 2881 904 3083 534 287 100 2216 2925 2368 212 2060 120 1557 2088 576 2183 1301 165 614 1185 2188 1085 280 3207 1921 513 2829 97 3085 324 1409 1115 4 543 797 2593 271 1586 3108 94 1284 1923 87 1168 2130 581 2413 2631 1887 15 157 2882 603 448 1296 2136 1190 3106 2571 1285 3081 6 2913 558 832 1933 ...
result:
ok OK!
Test #12:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
494 410 96 93 915 349 71 374 344 537 649 146 962 132 19 78 141 162 103 101 272 263 2 367 615 544 787 898 368 70 994 15 185 355 594 113 80 61 326 60 576 200 612 385 586 154 5 657 520 319 528 58 271 194 274 290 377 369 9 769 362 125 614 50 102 651 393 74 371 810 682 375 519 583 98 64 119 387 424 391 3...
output:
613 267 930 108 674 152 649 35 482 374 332 61 379 300 305 370 777 920 922 107 552 45 656 408 335 232 125 131 137 29 368 834 8 424 138 299 962 521 320 271 307 411 114 261 324 186 366 295 704 392 321 112 808 105 73 514 130 86 170 17 898 409 329 921 372 54 133 0 197 341 648 312 280 265 25 904 608 594 6...
result:
ok OK!
Test #13:
score: 0
Accepted
time: 711ms
memory: 50120kb
input:
199969 8669248 1075841048 201328650 44042242 577154 1477480448 75844 406986886 1209534848 37758482 402981064 8462848 67126848 36160 35783200 268500996 25297024 203492360 138412736 1243643904 180232 570441730 272732160 67568128 52564512 570886432 34016 1225073920 536940936 1074372864 4556832 26850128...
output:
1078462208 70 70676 537657380 1610617152 629164036 1090523264 1677787392 543293994 738217984 2662400 53506 136317090 8663584 10027074 32778 38013440 270401536 1107299352 809959488 75906 84410384 3153936 134793252 1744830592 1157668880 528896 581959746 1342187520 11798624 26746944 1073746624 11118202...
result:
ok OK!
Test #14:
score: 0
Accepted
time: 510ms
memory: 42580kb
input:
190281 53740576 202441232 536983640 1145053184 202703424 706479124 537213456 135726400 322181124 369160232 264208 16875750 536984090 604439104 254017728 538217476 672404500 12716036 1075089440 401830 310411820 1357398048 201721088 151389008 67162128 302098580 385933344 310487132 134481938 1144115456...
output:
1879085060 554042656 14680868 135320848 553780528 4329986 402685962 620757520 1610646560 25166916 939631170 395024 152438048 152044816 537944068 1394610176 38404616 539038002 857737220 21070400 75858 537930240 554762352 605094944 327163948 8389154 8389276 1618493984 805417544 138412572 536908832 134...
result:
ok OK!
Test #15:
score: 0
Accepted
time: 700ms
memory: 49992kb
input:
199998 344064132 2066 301989920 83886244 1744994560 84017920 704909320 1090847234 1354825984 19407360 42205408 436469796 67963392 34621480 35652096 100673568 34734336 285356032 136316320 536912388 50667520 9199616 2099392 2621792 285220880 1182088 1581074 50320 17111168 67747856 20987920 672661780 1...
output:
675299600 32868 2113602 134742856 271323136 42027012 1409368082 201457952 538738752 180388096 21103874 1623195904 139461056 67645568 277087232 269501456 1076117504 1145046016 4475394 266632 68817156 269490182 4722948 34897922 1107821058 537166432 20971552 71712 135792160 167786500 98374 1375731848 4...
result:
ok OK!
Test #16:
score: 0
Accepted
time: 1059ms
memory: 89456kb
input:
199984 4402408632320 9034687045437440 18155138279542816 2269533733650432 9077568067863552 45176733762093056 4503668347109380 68719501312 563500280252416 10133374039506944 567382359670784 4329570308 144255925568405504 848827271610432 288233124932880384 162411061562179648 108086700294537232 2199137340...
output:
4503602848727042 70368878444544 9007269047960576 18300273680318980 72075187297749120 4406636855296 72066390265167872 140737488359432 281477126422656 8798240510080 36029355968692240 18015498021110144 3298568438280 1266637495894016 1143493435064324 148176371872 145276272354788480 35321811174400 467955...
result:
ok OK!
Test #17:
score: 0
Accepted
time: 610ms
memory: 58392kb
input:
175134 108086408238334020 144115773533585824 72058968499306884 2533755843543040 146828920228937728 9007199254873088 218459768464475136 585474548627931136 281492160856100 2432326030065664 1460168630026244 2286997087993924 657811695644704776 146649631097389056 594479548859424768 2287544695799808 36029...
output:
9592173800460296 576465150383572992 36591747375038464 144296607628657152 1443243229696 432416002299400336 1099520278672 108367868214657032 1178676741800960 144398037442134528 272630784 9148488646656000 36030996075790336 180732374811136 72057595783351560 9147941038850116 72620819339559040 21620796863...
result:
ok OK!
Test #18:
score: 0
Accepted
time: 785ms
memory: 73412kb
input:
198623 17188785152 687750512640 70403108110912 4471062004740 8590526656 35184372097280 1125901047694464 105561706332160 2201206521856 4399205466112 140737926660112 2815377939628040 309287979136 211123412402176 166912 422212465131688 569547159506984 1161153003683904 3377699787702272 79440788857120 70...
output:
1409578201792518 4400194125824 36283901544448 556077120 1099780096032 422495932909696 17695407865856 1103824424960 4362076800 45902504448 1166040671193864 1237890121728 536941064 2260596074483714 71502615560320 598134342306816 281474977923588 8804783640576 88315265028 35184406168704 141304432954400 ...
result:
ok OK!
Test #19:
score: 0
Accepted
time: 855ms
memory: 71508kb
input:
199906 137438955040 23090817991168 139787763728 22541064208400 1236950606384 71468256591872 1099516354560 134480416 4400261120514 6597069864960 84021504 68720590856 2203318239234 8615116800 17729910226944 68753162498 9668003908 137440596000 35193029263360 6597069767756 27487808618626 79182017075232 ...
output:
4983235805184 549761335296 18176301596676 2147620384 893906845700 4398051836928 554059448384 17596481012800 18692771422208 26389369585680 168362050 35184380493984 268599328 35184408265216 2268825063424 4296278016 139587518592 2156134672 70506721116160 1099520147728 110020016472576 57178899743360 226...
result:
ok OK!