QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#766325 | #8322. 魔法手杖 | dieselhuang | 0 | 536ms | 325740kb | C++14 | 2.2kb | 2024-11-20 16:58:08 | 2024-11-20 16:58:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef __int128 lll;
static char buf[1000000],*p1=buf,*p2=buf;
#define GC() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++)
#define PC(x) putchar(x)
int read(){
int x = 0; char c = GC();
while(c < '0' || c > '9') c = GC();
while(c >= '0' && c <= '9'){
x = (x << 3) + (x << 1) + c - '0'; c = GC();
}
return x;
}
lll Read(){
lll x = 0; char c = GC();
while(c < '0' || c > '9') c = GC();
while(c >= '0' && c <= '9'){
x = (x << 3) + (x << 1) + c - '0'; c = GC();
}
return x;
}
void Write(lll x){
if(x >= 10) Write(x / 10);
PC(x % 10 + '0');
}
int Sub, n, m, k, tot, b[100010], ch[12000010][2];
ll sum[12000010];
lll N, ans, a[100010], mn[12000010];
bool chk(){
int i;
ll x = 0;
lll y = N;
for(i = 1; i <= n; i++) x += b[i], y = min(y, a[i]);
if(x <= m){
ans = y + N;
return true;
}
return false;
}
int add(){mn[++tot]=N;sum[tot]=ch[tot][0]=ch[tot][1]=0;return tot;}
void upd(lll x, int y){
int i, j, u = 1;
for(i = k - 1; 1; i--){
mn[u] = min(mn[u], x);
sum[u] += y;
if(i <= 0) break;
j = x >> i & 1;
if(ch[u][j] == 0) ch[u][j] = add();
u = ch[u][j];
}
}
void dfs(int o, int d, int m0, lll x, lll y, lll z){
if(d < 0){ ans = max(ans, z); return; }
lll u = ((lll)1 << d), v = u - 1;
if(o <= 0){ ans = max(ans, y + (x | u | v)); return; }
int lc = ch[o][0], rc = ch[o][1];
bool fl = false;
if(sum[lc] <= m0 && x + min(y, mn[lc]) > z){
dfs(rc, d - 1, m0 - sum[lc], x, min(y, mn[lc]), z | u); fl = true;
}
if(sum[rc] <= m0 && (x | u) + min(y, mn[rc]) > z){
dfs(lc, d - 1, m0 - sum[rc], x | u, min(y, mn[rc]), z | u); fl = true;
}
if(!fl){
dfs(lc, d - 1, m0, x, y, z);
dfs(rc, d - 1, m0, x | u, y, z);
}
}
void solve(){
ans = 0; tot = 1; sum[0] = ch[1][0] = ch[1][1] = 0;
int i;
n = read(); m = read(); k = read();
N = ((lll)1 << k) - 1;
for(i = 1; i <= n; i++){
a[i] = Read();
}
for(i = 1; i <= n; i++){
b[i] = read();
upd(a[i], b[i]);
}
if(chk()){ Write(ans); PC('\n'); return; }
dfs(1, k - 1, m, 0, N, 0);
Write(ans); PC('\n');
}
int main()
{
Sub = read();
int t = read();
while(t--) solve();
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 9680kb
input:
1 2 1 1 10 69 0 9 1000000000 10 244 710 380 144 439 863 870 166 346 495676227 842003627 148079269 750582321 584950601 767126829 909307499 254106473 942938842
output:
1092 1150
result:
wrong answer 2nd lines differ - expected: '479', found: '1150'
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 9792kb
input:
2 2 1 1 10 523 0 9 1000000000 10 848 862 206 186 563 318 692 557 937 922116005 577545690 363781833 81032507 443868714 352716275 50542823 305806582 28805127
output:
1546 697
result:
wrong answer 2nd lines differ - expected: '681', found: '697'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 11832kb
input:
3 2 1 1 10 98 0 9 1000000000 10 329 357 633 469 110 721 457 238 51 40948203 144541423 719902898 403414385 625735025 473335146 107749900 238792543 449945390
output:
1121 653
result:
wrong answer 2nd lines differ - expected: '511', found: '653'
Test #4:
score: 0
Wrong Answer
time: 110ms
memory: 49780kb
input:
4 5 100000 0 30 76630934 108936482 130420626 131855744 105346843 128458246 108243259 68059982 126654362 129080907 113416035 106976866 67840827 131702105 31856035 114313339 128664146 83795983 89307173 119627353 87072570 90008429 101830816 86771207 109365348 78483596 96660700 94183829 84341841 6114378...
output:
939540479 939524095 1065353215 939540479 939524095
result:
wrong answer 2nd lines differ - expected: '1073610765', found: '939524095'
Test #5:
score: 0
Wrong Answer
time: 129ms
memory: 49780kb
input:
5 5 100000 0 30 76630412 108936989 130419821 131855908 105346921 128458123 108243250 68060024 126653456 129080620 113415939 106976648 67840659 131702589 31855988 114313916 128664271 83796359 89307559 119627595 87072119 90007889 101830798 86770759 109365415 78484075 96661493 94184047 84342493 6114315...
output:
939540479 1610612734 1065353215 939540479 805306367
result:
wrong answer 2nd lines differ - expected: '1073610765', found: '1610612734'
Test #6:
score: 0
Wrong Answer
time: 113ms
memory: 47088kb
input:
6 5 100000 0 30 76630333 108936734 130420608 131855493 105346592 128458438 108243159 68059640 126653892 129080993 113415838 106976338 67840970 131701923 31855999 114313236 128664302 83796315 89307977 119627172 87072644 90007888 101831307 86771011 109365285 78483904 96661399 94183858 84341903 6114386...
output:
939540479 1610612734 1065353215 939540479 939524095
result:
wrong answer 2nd lines differ - expected: '1073610765', found: '1610612734'
Test #7:
score: 0
Wrong Answer
time: 94ms
memory: 12352kb
input:
7 250000 2 1 16 40654 60936 1 2 2 1 5 29 18 1 2 2 1 9 367 278 1 2 2 1 6 32 40 1 2 2 1 28 211414711 120442951 1 2 2 1 9 440 62 1 2 2 1 2 2 2 1 2 2 1 6 60 1 1 2 2 1 1 0 0 1 2 2 1 16 39195 9530 1 2 2 1 19 260304 52003 1 2 2 1 12 1492 2878 1 2 2 1 22 2112709 2056045 1 2 2 1 30 840827142 778131799 1 2 2 ...
output:
98302 46 766 94 412741302 479 4 63 1 57343 491519 3539 5258436 1610612734 1534 251658239 1006632959 27 12750967 9094075 380820 49 193552 229375 4496 50331646 1 16515071 1 402653183 917503 223 46328856 92 10 895 6051001 805306366 4 393214 1 1 24574 3242 12582910 94 14680063 94 3145727 98302 25564183 ...
result:
wrong answer 1st lines differ - expected: '55295', found: '98302'
Test #8:
score: 0
Wrong Answer
time: 83ms
memory: 12888kb
input:
8 250000 2 1 24 7245747 7751903 1 2 2 1 18 7301 21614 1 2 2 1 2 1 3 1 2 2 1 3 0 4 1 2 2 1 22 1946046 3459042 1 2 2 1 1 0 1 1 2 2 1 27 110608129 62075905 1 2 2 1 7 79 78 1 2 2 1 1 0 0 1 2 2 1 8 190 156 1 2 2 1 29 213608577 61390223 1 2 2 1 21 194242 1613306 1 2 2 1 8 46 195 1 2 2 1 12 2674 3172 1 2 2...
output:
12582911 245759 2 3 4043197 1 211271424 190 1 382 503316479 1242817 173 6142 1 108 393215 114687 196606 1835007 100663294 5453677 1793 51 3946502 3148 13 12582910 10 98302 24574 324155 1 23 1919 1791 14335 223 402653182 7 3070 50331646 50331646 1 22 34 98302 2064383 3070 14115520 123 12582910 94 3 8...
result:
wrong answer 1st lines differ - expected: '16515071', found: '12582911'
Test #9:
score: 0
Wrong Answer
time: 87ms
memory: 47732kb
input:
9 40003 100000 1 30 76630623 108936745 130419844 131856358 105346889 128458736 108243812 68059447 126654184 129080977 113416077 106976936 67840619 131702296 31855896 114313546 128664506 83796193 89307481 119627719 87072176 90007912 101831608 86771305 109366220 78484119 96661356 94183598 84341931 611...
output:
939540479 1610612734 1065353215 3005 402653183 3071 992 4194303 469762047 29360127 22429 3071 1933 11 28671 318 2359294 10485758 1 3 10485758 61439 44907914 1048989663 14680063 109 6143 849298282 671088638 402653183 7 3145727 163838 524287 4194303 390051 78 2558 8389241 148759809 100663295 327678 17...
result:
wrong answer 2nd lines differ - expected: '1073610765', found: '1610612734'
Test #10:
score: 0
Wrong Answer
time: 86ms
memory: 45440kb
input:
10 40003 100000 1 30 76630457 108937083 130420232 131855828 105346260 128458262 108242996 68059167 126653670 129080772 113416051 106976793 67840568 131702468 31855850 114313412 128664110 83796459 89307450 119627418 87071762 90007680 101831024 86771509 109365868 78483555 96661066 94183460 84342625 61...
output:
939540479 805306367 1065353215 119200937 2621438 88450194 6300883 150994942 766 4095 78 201326590 767 75124094 33554431 6143 163838 6142 20334 2830 23 24575 511 196606 2359294 29 134217727 786430 98302 57202 12582910 95 524287 1187963 61439 2 536870911 78 393214 7 638 402653182 5 786430 63 1217 255 ...
result:
wrong answer 2nd lines differ - expected: '1073610765', found: '805306367'
Test #11:
score: 0
Wrong Answer
time: 90ms
memory: 47220kb
input:
11 40003 100000 1 30 76630674 108936653 130420433 131856265 105346983 128458653 108243409 68059656 126653505 129080757 113415755 106976914 67840002 131701979 31855773 114313774 128664187 83796634 89307850 119627507 87071827 90007813 101831495 86771399 109365557 78483822 96660811 94184023 84342680 61...
output:
939540479 939524095 1065353215 31 105 2720 33554431 1 46810 10 4718590 1502629 895 100663294 318 7081274 786431 234881023 10485758 4194303 1 14556 18 134217727 31 8126463 1845711773 5 10485758 50331646 7 18 638 720895 5 402653183 46 126847731 31498 1 8388607 75497470 40958 111 4194303 1610612734 62 ...
result:
wrong answer 2nd lines differ - expected: '1073610767', found: '939524095'
Test #12:
score: 0
Wrong Answer
time: 80ms
memory: 49732kb
input:
12 40003 100000 1 30 76630775 108937143 130420127 131855472 105346114 128458369 108243185 68060064 126653745 129080952 113415931 106976535 67841016 131701837 31855974 114313669 128664055 83796306 89307860 119626895 87072131 90008292 101831649 86771064 109366112 78484048 96660693 94184079 84342338 61...
output:
939540479 1610612734 1065353215 1278 432 13031 98303 12031 196606 3 49151 6291455 3339247 239 1 82926 163838 6645 20971518 47 1964794 3932159 36 3670015 18430 805306366 255 11263 458751 100663294 4095 20971518 1470884600 10238 247 7 121155156 258312620 1654363958 1 7127974 49151 383 469762047 419430...
result:
wrong answer 2nd lines differ - expected: '1073610767', found: '1610612734'
Test #13:
score: 0
Wrong Answer
time: 72ms
memory: 45336kb
input:
13 40003 100000 1 30 76630774 108936584 130420001 131856305 105347060 128457982 108243169 68059620 126654022 129081029 113415335 106976790 67840471 131702040 31855824 114314232 128663903 83796420 89307827 119626984 87072029 90008558 101830939 86770995 109365419 78483800 96660514 94183753 84342755 61...
output:
939540479 939524095 1065353215 13860 41943038 327678 5320634 221158213 2621438 3145726 619401751 1310718 4088696 2035055117 33554431 18 614 718 255 24574 117 196607 236819 196606 1835007 3 39 115993780 7 40958 3 10465754 33554431 10485758 18 4431 1331759 3583 219604519 1572863 1535 1791 111 50331646...
result:
wrong answer 2nd lines differ - expected: '1073610767', found: '939524095'
Test #14:
score: 0
Wrong Answer
time: 1ms
memory: 9700kb
input:
14 5 100 1000000000 30 13132 1189 129473 100435 99142 27988 125913 84108 88618 104500 18510 127909 33713 41539 73168 52981 93666 111173 97215 18318 116125 48796 66468 68341 66995 8141 6453 78522 5137 102161 79767 83305 55735 35923 57672 40415 26124 3517 89580 103805 63333 70578 15006 115257 25327 11...
output:
1073641471 1006632959 1073217535 1073643519 1610612734
result:
wrong answer 2nd lines differ - expected: '1073741724', found: '1006632959'
Test #15:
score: 0
Wrong Answer
time: 1ms
memory: 9888kb
input:
15 5 100 1000000000 30 13147 1100 129952 101117 98742 27859 125802 84826 88433 104546 18804 127522 33108 41885 72848 52261 94114 110852 97024 17835 116004 48702 65612 68427 67541 7813 6415 78436 5289 102296 78964 83467 56256 36720 58141 39956 25783 3977 89405 104251 63057 69881 14546 115008 24936 10...
output:
1073641471 1610612734 1073217535 1073642495 1610612734
result:
wrong answer 2nd lines differ - expected: '1073741726', found: '1610612734'
Test #16:
score: 0
Wrong Answer
time: 12ms
memory: 25228kb
input:
16 4003 10000 1000000000 60 6301301488220013 13036910415217886 3587708952967093 9679001900905121 15370074903700843 10699351669343223 3693263165367499 11069887286230748 16712579672850495 7401912839403587 2739985286259605 4571772340856038 7048969239142713 1894459710006182 17112800883496323 12320029364...
output:
1134974176306659327 1152358554653425663 1152640029630136319 10485758 4503597479886847 135291469823 272730423295 587086 12287 2848000 222778326 18014397435740159 70368475742207 77882378 9007197107257343 337832773 273804165119 2621438 1125897759358975 5 281472829227007 3583 399753261 562947805937663 7...
result:
wrong answer 2nd lines differ - expected: '1152921504606830652', found: '1152358554653425663'
Test #17:
score: 0
Wrong Answer
time: 15ms
memory: 26860kb
input:
17 4003 10000 1000000000 60 6301301819534654 13036910822653667 3587709968963537 9679000983663529 15370074961371554 10699347928378657 3693263473368908 11069883997526525 16712580951412763 7401916234416503 2739986911540418 4571770484223398 7048969495053322 1894461412350279 17112799936179837 12320030978...
output:
1134973076795031551 1152640029630136319 1152640029630136319 8388607 3221225471 36028794871480319 4503597479886847 140735340871679 4503599090499583 2197949513727 16 1843095 3218 7 1 140735072436223 7856127 1342177278 281472829227007 20 70367670435839 24575 1048575 4503597479886847 140736414613503 15 ...
result:
wrong answer 2nd lines differ - expected: '1152921504606830653', found: '1152640029630136319'
Test #18:
score: 0
Wrong Answer
time: 21ms
memory: 24176kb
input:
18 4003 10000 1000000000 60 6301305150188370 13036910274580735 3587707298181505 9679004703165232 15370075141428877 10699349494581236 3693260766091278 11069885717856260 16712580184551432 7401916423007610 2739984412836669 4571773004118082 7048970479824295 1894458866748282 17112803260092779 12320029000...
output:
1134977474841542655 1152358554653425663 1152640029630136319 229375 622204 35182224605183 1787 1610612735 657840 288230375077969919 10 281473902968831 67108863 402653183 70367670435839 8793945538559 25165822 3758096383 1380810 70367670435839 1900579281 511 98303 103761442 2251797666201599 28823037504...
result:
wrong answer 2nd lines differ - expected: '1152921504606830655', found: '1152358554653425663'
Test #19:
score: 0
Wrong Answer
time: 265ms
memory: 16828kb
input:
19 62501 100000 1000000000 120 1154838249421518343773531773357597778 1154838249421518343773531773357629327 1154838249421518343773531773357650307 1154838249421518343773531773357651709 1154838249421518343773531773357625821 1154838249421518343773531773357648391 1154838249421518343773531773357628650 115...
output:
1993841993677373809355710590420516862 2326148992623602777581662355490602998 1163074496311801388790831177745301503 1246151246048358630847319119012823039 1993841993677373809355710590420516862 1163074496311801388790831177745301503 1993841993677373809355710590420516862 2326148992623602777581662355490603...
result:
wrong answer 1st lines differ - expected: '1329227995784915872903807060280213591', found: '1993841993677373809355710590420516862'
Test #20:
score: 0
Wrong Answer
time: 262ms
memory: 17060kb
input:
20 62501 100000 1000000000 120 323632031276481459143358069001495634 323632031276481459143358069001527183 323632031276481459143358069001548163 323632031276481459143358069001549565 323632031276481459143358069001523677 323632031276481459143358069001546247 323632031276481459143358069001526506 3236320312...
output:
1163074496311801388790831177745301503 2326148992623602777581662355490602998 1993841993677373809355710590420516862 1993841993677373809355710590420516862 1993841993677373809355710590420516862 1318843402067846217646746067621904383 2326148992623602777581662355490603000 2326148992623602777581662355490602...
result:
wrong answer 1st lines differ - expected: '1329227995784915872903807060280213599', found: '1163074496311801388790831177745301503'
Test #21:
score: 0
Wrong Answer
time: 390ms
memory: 325740kb
input:
21 62501 100000 1000000000 120 94863733210630102424008628084424216 134857169996406520360367913319523910 161452665267901932764497978184577026 163229916633468866695669655916793917 130413130894076501442669761804067887 159024080878679252370015542440688101 133998758779238309221865949392709341 84253191505...
output:
1163193655468222842354571867846606847 1246151246048358630847319119012823039 2326148992623602777581662355490602999 1993841993677373809355710590420516862 1246151246048358630847319119012823039 1993841993677373809355710590420516862 1993841993677373809355710590420516862 1993841993677373809355710590420516...
result:
wrong answer 2nd lines differ - expected: '1329227995784915872903807060280344575', found: '1246151246048358630847319119012823039'
Test #22:
score: 0
Wrong Answer
time: 462ms
memory: 17004kb
input:
22 120001 100000 1000000000 120 47471234275189825886337730002101330 47471234275189825886337730002132879 47471234275189825886337730002153859 47471234275189825886337730002155261 47471234275189825886337730002129373 47471234275189825886337730002151943 47471234275189825886337730002132202 4747123427518982...
output:
1287689620916637251875563089646583807 1993841993677373809355710590420516862 1324035698926381045275276563951124479 1308458808350776562389685074963464191 1993841993677373809355710590420516862 1246151246048358630847319119012823039 1993841993677373809355710590420516862 1993841993677373809355710590420516...
result:
wrong answer 1st lines differ - expected: '1329227995784915872903807060280213591', found: '1287689620916637251875563089646583807'
Test #23:
score: 0
Wrong Answer
time: 535ms
memory: 295636kb
input:
23 120001 100000 1000000000 120 10384594543745281933157089286344285 10384595087221325583432181750603761 10384596344313448100419024142756824 10384597896452402824418716086599406 10384599662161038685053136018241571 10384600136159512396111755729028709 10384601958291386084902861505361244 1038460344973912...
output:
1318843402067846217646746067621904383 1993841993677373809355710590420516862 2326148992623602777581662355490603002 1993841993677373809355710590420516862 2326148992623602777581662355490602998 1993841993677373809355710590420516862 1993841993677373809355710590420516862 1163074496311801388790831177745301...
result:
wrong answer 1st lines differ - expected: '1329104226539788120583922645840429055', found: '1318843402067846217646746067621904383'
Test #24:
score: 0
Wrong Answer
time: 525ms
memory: 293824kb
input:
24 120001 100000 1000000000 120 10384594585679242355840829886289379 10384595083750076569134324633632941 10384596423425537641166720528386677 10384598270636404608178558554968102 10384598723408000881156593449465505 10384600392016296777984789088889743 10384602014485619490959986853506329 1038460298717050...
output:
1318843402067846217646746067621904383 1246151246048358630847319119012823039 1993841993677373809355710590420516862 1163074496311801388790831177745301503 2326148992623602777581662355490602997 1246151246048358630847319119012823039 1993841993677373809355710590420516862 1246151246048358630847319119012823...
result:
wrong answer 1st lines differ - expected: '1329104229015668199154683195638677503', found: '1318843402067846217646746067621904383'
Test #25:
score: 0
Wrong Answer
time: 536ms
memory: 293876kb
input:
25 120001 100000 1000000000 120 10384594059032377855972206804990515 10384595922446112233978399250497752 10384596677646074836565734489994716 10384597585175584397302672981127521 10384599121981302637859909713499899 10384600188980133483790411300324684 10384601157708131158985167495674683 1038460244379676...
output:
1318843402067846217646746067621904383 1993841993677373809355710590420516862 2326148992623602777581662355490602999 2326148992623602777581662355490603000 1993841993677373809355710590420516862 1163074496311801388790831177745301503 1993841993677373809355710590420516862 1993841993677373809355710590420516...
result:
wrong answer 1st lines differ - expected: '1329104231491548277725443745436925951', found: '1318843402067846217646746067621904383'