QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#33164 | #1817. AND Permutation | bulijiojiodibuliduo# | AC ✓ | 757ms | 121924kb | C++ | 1.4kb | 2022-05-29 03:19:18 | 2022-05-29 03:19:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
vector<pair<ll,ll>> build(vector<ll> v,int b) {
if (v.empty()) return vector<pair<ll,ll>>(0);
if (v.size()==1) {
return vector<pair<ll,ll>>{mp(v[0],v[0])};
}
vector<ll> v0,v1;
for (auto x:v) if (x&(1ll<<b)) v1.pb(x-(1ll<<b)); else v0.pb(x);
auto ans0=build(v0,b-1),ans1=build(v1,b-1);
set<ll> o(all(v1));
for (auto &v:ans0) if (o.count(v.se)) v.se+=1ll<<b;
for (auto &v:ans1) v.fi+=1ll<<b;
vector<pair<ll,ll>> ans;
int p0=0,p1=0;
for (auto x:v) if (x&(1ll<<b)) ans.pb(ans1[p1++]);
else ans.pb(ans0[p0++]);
return ans;
}
int main() {
int n;
scanf("%d",&n);
vector<ll> v;
rep(i,0,n) {
ll x;
scanf("%lld",&x),v.pb(x);
}
auto ans=build(v,59);
rep(i,0,n) printf("%lld\n",ans[i].se);
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3804kb
input:
6 0 1 4 5 2 6
output:
5 6 1 2 4 0
result:
ok OK!
Test #2:
score: 0
Accepted
time: 3ms
memory: 4104kb
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:
132 116 384 313 36 22 211 46 131 310 246 314 34 122 303 209 190 168 129 3 67 336 337 92 260 13 267 322 198 283 192 279 19 10 309 321 240 263 153 287 224 282 289 142 276 14 290 112 182 228 130 144 416 66 15 268 32 302 250 16 226 35 82 138 266 280 58 194 256 53 277 23 44 134 135 304 257 422 11 301 31 ...
result:
ok OK!
Test #3:
score: 0
Accepted
time: 15ms
memory: 8284kb
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:
20624 33155 33032 1094 109840 70018 24848 35216 67880 85480 105763 35873 39553 18561 3532 85324 1224 81920 83076 4992 66660 40064 9472 106017 12292 16529 67976 3472 8720 6560 69922 104707 3745 99345 34000 69865 73506 3232 61478 1697 36480 3204 65868 39554 45090 19088 2566 8576 44288 99618 17676 7065...
result:
ok OK!
Test #4:
score: 0
Accepted
time: 2ms
memory: 3812kb
input:
15 10 0 11 13 2 14 4 1 5 6 8 12 3 7 9
output:
5 7 4 2 13 0 11 14 10 9 3 1 12 8 6
result:
ok OK!
Test #5:
score: 0
Accepted
time: 3ms
memory: 6748kb
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:
22533 16560 19408 25537 16960 15376 6165 24588 2053 29221 277 513 25252 6856 20864 15409 10248 560 24100 1122 12289 26292 2625 11184 27444 10754 210 11029 25748 6280 17220 30768 10321 31269 11668 26833 4608 3029 3089 2512 8852 2480 1147 3585 2144 14900 597 10900 27328 120 9472 24116 32288 8533 16532...
result:
ok OK!
Test #6:
score: 0
Accepted
time: 2ms
memory: 3780kb
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: 3ms
memory: 4196kb
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 320 2 190 304 277 40 418 72 403 191 394 271 137 443 11 130 414 121 5 287 89 133 174 151 27 148 274 441 39 447 46 278 24 407 163 312 260 128 50 146 440 187 54 257 273 411 19 422 264 26 426 57 389 419 432 159 13 44 401 437 42 4 279 81 404 276 80 49 136 262 168 34 112 170 104 428 427 405 186 169 30...
result:
ok OK!
Test #8:
score: 0
Accepted
time: 3ms
memory: 4148kb
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 23 851 860 336 788 859 264 68 527 320 70 781 13 577 11 861 15 324 22 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 855 837 836 852 9 269 93 606 515 584 2 532 790 263 599 586 286 8...
result:
ok OK!
Test #9:
score: 0
Accepted
time: 2ms
memory: 3996kb
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:
3 13 65 0 157 28 72 211 131 18 6 30 146 161 134 97 115 15 25 141 136 178 145 135 242 197 51 98 83 156 194 32 9 153 26 241 138 154 243 20 144 67 227 64 160 21 148 73 204 68 19 22 35 240 155 69 130 112 76 24 205 162 209 42 132 23 168 177 34 225 8 77 196 142 163 195 16 14 82 7 137 159 193 158 192 226 1...
result:
ok OK!
Test #10:
score: 0
Accepted
time: 0ms
memory: 3856kb
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:
5 16 0 26 1 28 3 17 19 24 8 6 22 25 11 10 12 7 9 20 27 18 2 4
result:
ok OK!
Test #11:
score: 0
Accepted
time: 6ms
memory: 5400kb
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:
1935 196 906 1302 551 815 5 2184 2092 1362 110 1068 8 581 2121 593 2919 325 277 526 2337 2188 109 298 3215 1923 537 1868 2913 1300 2228 1411 1035 23 1551 1805 2625 3853 610 1316 854 3220 1927 1631 1152 848 605 2084 1600 1558 838 77 2816 907 176 1168 336 2094 1318 793 1309 1298 310 49 606 177 1928 33...
result:
ok OK!
Test #12:
score: 0
Accepted
time: 3ms
memory: 4288kb
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:
577 287 930 104 674 184 649 551 482 274 297 40 315 364 177 304 793 920 922 111 632 381 656 408 71 232 25 15 185 8 368 834 28 424 270 303 962 57 323 39 261 387 518 48 289 378 362 403 704 395 453 624 268 109 93 134 14 374 154 21 898 385 461 921 272 530 309 140 192 320 648 120 56 285 319 904 76 578 536...
result:
ok OK!
Test #13:
score: 0
Accepted
time: 590ms
memory: 121924kb
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:
557875472 16818400 553665044 150996004 73609216 537198592 50495626 1652818432 807404032 226543616 5243906 1078071310 675317762 152192 71304210 18458 302006282 839008256 75500576 826408960 1074069542 1073777164 553656392 20451328 549454856 219676672 17438978 302137344 269617158 68554752 549060608 553...
result:
ok OK!
Test #14:
score: 0
Accepted
time: 507ms
memory: 112956kb
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:
1879087108 554042720 14811650 137483536 553780528 4329992 402686026 620757552 75531296 25166916 939635274 4596480 219545664 152044848 537944076 14684192 38404616 539038514 857738244 21070400 75984 537930368 554762864 605094944 327165024 8389224 8393804 1610613408 805417544 138421264 537071648 135536...
result:
ok OK!
Test #15:
score: 0
Accepted
time: 616ms
memory: 118356kb
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:
672139296 748 536870990 33571648 2359808 135273472 270598400 68813824 620757056 113249280 1095238400 1610616976 11666432 134840448 83890182 402702400 136325122 1611153538 272640512 8471560 210370816 158334980 33690370 12584576 536872258 270607872 270827652 1078006018 77734912 3538944 612402178 13463...
result:
ok OK!
Test #16:
score: 0
Accepted
time: 757ms
memory: 46940kb
input:
199984 4402408632320 9034687045437440 18155138279542816 2269533733650432 9077568067863552 45176733762093056 4503668347109380 68719501312 563500280252416 10133374039506944 567382359670784 4329570308 144255925568405504 848827271610432 288233124932880384 162411061562179648 108086700294537232 2199137340...
output:
79173427134472 8913408 9009411162898432 9079560864256 1126449939480576 35185454219328 72066424490819648 1108101660680 4417373863936 8804716519424 36029363954909200 18015499631727616 70368746340354 19140299490066436 1161086426415136 85900394496 144150372984815648 6790584081580096 9007201403273216 144...
result:
ok OK!
Test #17:
score: 0
Accepted
time: 525ms
memory: 30676kb
input:
175134 108086408238334020 144115773533585824 72058968499306884 2533755843543040 146828920228937728 9007199254873088 218459768464475136 585474548627931136 281492160856100 2432326030065664 1460168630026244 2286997087993924 657811695644704776 146649631097389056 594479548859424768 2287544695799808 36029...
output:
9592173800460296 576465150383572992 36591747375038464 144296607628657152 1443243262464 432416002299400592 1099520278672 108368143092563976 1178676741800960 144398037442134528 272630816 9148488646656000 36030996075790336 180732374811136 72057595783351560 9147941038850116 72620819339559040 21620796863...
result:
ok OK!
Test #18:
score: 0
Accepted
time: 687ms
memory: 63140kb
input:
198623 17188785152 687750512640 70403108110912 4471062004740 8590526656 35184372097280 1125901047694464 105561706332160 2201206521856 4399205466112 140737926660112 2815377939628040 309287979136 211123412402176 166912 422212465131688 569547159506984 1161153003683904 3377699787702272 79440788857120 70...
output:
1409711345762472 4400194126856 36283901562880 2185232448 22093311771392 422495932973096 17695407865872 1104092862464 4362076808 70371432726528 1130297953946112 4398047035424 536944672 2260598223015938 71502617714696 598134342420480 281474980905024 281509338546192 88315269636 35184406691848 141836999...
result:
ok OK!
Test #19:
score: 0
Accepted
time: 700ms
memory: 76064kb
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:
1120986499328 295936 18176305793032 2151940096 3023656980480 4402350948352 549848104960 17596482068738 35738422968320 26389357004800 8796261851136 35184452042768 273678608 2233550766144 37385542893568 19791210086432 70388206272512 551905395712 70508867764224 8797171058688 37383663779840 8589950976 2...
result:
ok OK!