QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#165804#2593. 甲苯先生的线段树Bronya100 ✓481ms4032kbC++201.9kb2023-09-05 21:53:172023-09-05 21:53:18

Judging History

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

  • [2023-09-05 21:53:18]
  • 评测
  • 测评结果:100
  • 用时:481ms
  • 内存:4032kb
  • [2023-09-05 21:53:17]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
const int mo=1000000007;
long long s;
int n;
int H1,H2;
long long ned;
long long f[55][102][2];
long long sav[55][102][2];
pair<int,int> sv[55][102][2];
long long calc(int now,int cnt,int jw){
    if(cnt<0)return 0;
    if((1ll<<now)>ned)return (cnt==0);
    if(ned/(1ll<<now)<cnt)return 0;
    if(sav[now][cnt][jw]==ned&&sv[now][cnt][jw]==make_pair(H1,H2))return f[now][cnt][jw];
    long long ans=0;sav[now][cnt][jw]=ned;sv[now][cnt][jw]=make_pair(H1,H2);
    int hav=(now<=H1)+(now<=H2);
    bool pd=(1ll<<now)&ned;
    if(jw==pd){
        ans+=calc(now+1,cnt,0);
        if(hav==2)ans+=calc(now+1,cnt-2,1);
    }
    else ans+=calc(now+1,cnt-1,jw)*hav;
    return f[now][cnt][jw]=ans;
}
void Solve(long long s){
    long long ans=0;
    for(int i=1;(1ll<<i)-1<=s;i++){
        long long x=s%((1ll<<i)-1),y=s/((1ll<<i)-1);
        if(__lg(y)+i>n)continue;
        for(int j=i-1;j>=1;j--)
            if(x>=(1ll<<j)-1)x-=(1ll<<j)-1;
        if(x==0)ans++;
    }
    for(int h1=1;((1ll<<h1)-1)*2+1<=s;h1++){
        for(int h2=1;((1ll<<h1)-1)*2+1+3*((1ll<<h2)-1)<=s;h2++){
            long long x=(s-((1ll<<h2)-1))%(((1ll<<h1)+(1ll<<h2)-2)*2+1);
            long long y=(s-((1ll<<h2)-1))/(((1ll<<h1)+(1ll<<h2)-2)*2+1);
            if(__lg(y)+max(h1,h2)+1>n)continue;
            if(!x){ans++;continue;}
            H1=h1-1;H2=h2-1;
            for(int i=1;i<=h1+h2-2;i++)
                if(!((x+i)&1)){ned=x+i;ans+=calc(1,i,0);}
        }
    }
    printf("%lld\n",ans-1);
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int op;
        long long a,b;
        scanf("%d%lld%lld%d",&n,&a,&b,&op);
        long long sum=a+b;
        while(a!=b){
            if(a<b)swap(a,b);
            sum+=a/2;a/=2;
        }
        sum-=a;
        if(op==1)printf("%lld\n",sum);
        else Solve(sum);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 1ms
memory: 3816kb

input:

10
7 118 79 1
6 9 1 1
8 166 97 1
6 52 61 1
10 412 712 1
7 104 22 1
6 16 9 1
7 22 100 1
9 450 432 1
6 16 21 1

output:

383
16
518
213
2238
245
37
237
1751
66

result:

ok 10 lines

Test #2:

score: 5
Accepted
time: 1ms
memory: 3684kb

input:

10
10 586 67 2
8 195 36 2
10 838 553 1
9 17 187 2
8 133 157 2
8 140 237 2
10 464 699 1
9 129 162 2
9 185 10 1
7 92 126 2

output:

168
55
2772
62
51
29
2314
74
372
11

result:

ok 10 lines

Test #3:

score: 5
Accepted
time: 2ms
memory: 3668kb

input:

10
17 50940 76532 2
15 19629 32478 2
17 3269 101070 1
12 553 495 1
12 1466 19 2
14 12130 6881 1
17 111341 121477 1
11 266 67 1
14 4715 8058 2
13 6396 1641 1

output:

34079
3388
208631
2083
353
38006
465611
565
3064
16028

result:

ok 10 lines

Test #4:

score: 5
Accepted
time: 10ms
memory: 3756kb

input:

10
25 29839566 8697543 2
24 9917413 11909116 2
14 15851 8952 1
16 27646 25719 1
25 2452059 22013853 2
20 1026526 477979 1
25 22514287 23343507 1
23 2482397 4296529 1
14 11584 4572 1
25 14676057 23774115 2

output:

7077482
3010266
49587
106695
6051795
3008970
91715551
13557820
32296
7148123

result:

ok 10 lines

Test #5:

score: 5
Accepted
time: 1ms
memory: 3620kb

input:

10
16 3142 11275 1
16 18266 54266 1
20 462861 285779 1
27 73766873 67316941 1
17 49540 54534 1
24 11613958 2395341 1
22 1413504 1733464 1
29 457490370 469372165 1
26 23969718 30356372 1
26 34852509 43354905 1

output:

28822
145044
1497263
282167580
208122
28018573
6293917
1853724966
108652147
156414798

result:

ok 10 lines

Test #6:

score: 5
Accepted
time: 213ms
memory: 3880kb

input:

10
28 114265538 95965183 2
33 1575521099 8205383869 1
46 49130665769587 62196641032987 2
28 250857209 188848505 2
32 2430055691 733585987 2
36 25466456697 35208326584 1
37 123257499566 58024370530 1
48 142921894349508 118376372404773 2
49 485635375612914 90028384708563 1
49 556016666222162 561573159...

output:

54004531
19561809901
7364672355012
24536577
789989273
121349566520
362563740152
64984263474778
1151327520642898
2055878519483

result:

ok 10 lines

Test #7:

score: 5
Accepted
time: 117ms
memory: 3900kb

input:

10
34 9154408383 16121783967 2
41 2062226037018 645745014544 1
37 75654342033 92838769261 2
33 2359018682 5563129362 1
39 345147043520 296949715030 2
42 1918266365232 1357406848332 2
46 61866964130712 63720681140210 1
29 235127440 121934462 2
35 27023970634 9746997413 1
32 3486383027 3211649293 2

output:

2241699194
5415942103089
26434833070
15844296052
115621385165
829420918131
251175290541722
90872764
73541936064
468296505

result:

ok 10 lines

Test #8:

score: 5
Accepted
time: 481ms
memory: 3996kb

input:

10
42 3938386955113 4156641303686 2
42 685772722434 693225693347 1
30 484613996 1010213134 2
49 309140778907674 204569446037383 2
30 397286893 915178655 2
49 338416836158659 210021978472037 2
30 1016980901 637577273 1
45 2501576683735 24990710495834 1
44 867975086587 2022622572611 2
30 417616765 820...

output:

175839984067
2757996831520
161921334
129325997632830
206117044
136445726142501
3309116319
54984574359085
724763796390
999345809

result:

ok 10 lines

Test #9:

score: 5
Accepted
time: 94ms
memory: 3804kb

input:

10
49 260585856251934 72871992498039 1
37 111150089402 91784653853 2
37 105937755997 16374820915 1
49 257480039657253 94677986988818 1
31 1798987305 620345850 1
47 98650754710359 7011245636024 1
27 84416576 95110022 1
40 275930058791 1019468981390 2
41 1627631127404 366008254529 2
48 168190488233303...

output:

666915697499898
18086310033
244625153783
704316053292090
4838666273
211324000692715
359053166
226716589960
495673595517
845959175978478

result:

ok 10 lines

Test #10:

score: 5
Accepted
time: 429ms
memory: 3820kb

input:

10
38 268836951952 62826903094 1
46 68383828842223 68573957313412 2
50 222257975061520 1072227674471140 2
42 1364139810948 74125602537 1
50 259773861893483 763120306799816 2
45 8003409440083 8943693121073 2
37 71658804341 106298119389 2
33 5730527990 1317955967 1
50 162128161755065 1060613826025902 ...

output:

663327710036
960536376652
240151801240230
2876530826924
255138846517172
4237665168296
24151316918
14096967873
2445483975561878
31802816927

result:

ok 10 lines

Test #11:

score: 5
Accepted
time: 1ms
memory: 3704kb

input:

10
6 45 48 1
10 455 207 1
6 13 6 1
8 224 5 1
6 37 25 1
6 28 13 1
9 70 477 1
9 239 273 1
8 16 241 1
9 468 120 1

output:

179
1307
19
452
117
71
1083
1013
507
1152

result:

ok 10 lines

Test #12:

score: 5
Accepted
time: 0ms
memory: 3868kb

input:

10
10 937 485 2
6 1 30 1
8 213 11 2
9 202 323 1
8 139 243 1
10 829 847 1
9 201 491 1
9 86 303 1
7 37 17 2
9 151 302 1

output:

137
56
40
1041
753
3324
1368
764
11
453

result:

ok 10 lines

Test #13:

score: 5
Accepted
time: 1ms
memory: 3704kb

input:

10
16 45633 65331 1
20 153001 74740 1
18 94604 237045 1
12 3404 2148 1
11 1186 1126 1
20 746974 798872 1
16 31452 46033 1
13 3497 4009 1
19 57590 242724 1
15 3854 7004 1

output:

221909
455414
663276
11093
4605
3091671
154950
14992
600575
21696

result:

ok 10 lines

Test #14:

score: 5
Accepted
time: 4ms
memory: 3924kb

input:

10
24 9417949 713016 2
16 34633 2092 1
25 19594483 22445033 1
15 20951 14102 2
22 1191213 1853905 1
18 191409 20632 2
22 2034040 3835800 1
21 119435 1770369 2
21 1207054 923715 1
19 463168 521307 2

output:

2498477
73393
84078996
7151
6090215
52466
11739643
471697
4261519
15068

result:

ok 10 lines

Test #15:

score: 5
Accepted
time: 1ms
memory: 3616kb

input:

10
26 65048154 55126561 1
29 499128773 103746945 1
24 5231425 962343 1
27 90248669 110204599 1
26 53066066 41140284 1
30 43397914 832460498 1
17 78768 115310 1
26 41800911 12406957 1
23 5678602 849142 1
26 39844952 60586413 1

output:

240349402
1205751406
12387510
400906506
188412674
1751716795
388138
108415702
13055464
200862697

result:

ok 10 lines

Test #16:

score: 5
Accepted
time: 34ms
memory: 4032kb

input:

10
27 79658299 7038138 1
49 556905873018741 502813031136512 1
26 50152166 12841385 1
33 1233651948 7295533985 1
47 100799955776456 66375566040789 2
40 1005965381817 831008015944 2
26 37142512 56050239 1
45 25014529378897 2556728843697 1
35 13875323121 7807669400 1
42 3519344738200 1692779865985 1

output:

173392841
2119437808310445
125987073
17058371839
28813567434274
89686080517
186385470
55142516445147
43365985005
10424249208297

result:

ok 10 lines

Test #17:

score: 5
Accepted
time: 203ms
memory: 3944kb

input:

10
48 27858350141966 38648389893507 1
47 74660740749641 132315391633792 2
49 298194028841067 486649105849844 2
28 188817049 110085386 2
38 164250346110 148036872507 2
43 6555094479746 639505481666 2
48 219752763142526 79881867723747 2
26 18605737 40927348 2
31 1464928198 1184993289 2
48 200338210007...

output:

133013480070903
18569454942825
85519277751973
59054068
58837097676
1808023394038
66650713783149
14800715
408888895
883117335312679

result:

ok 10 lines

Test #18:

score: 5
Accepted
time: 187ms
memory: 3800kb

input:

10
35 23506606577 3424639902 1
50 40246267142109 380529203899096 1
36 45306514507 66545922752 2
42 2826145646852 3094728333619 1
41 1827690363977 2086375330836 1
42 4223639710985 691235610931 2
50 556385922743928 1016351808824315 1
41 1081727281890 1283915329908 1
45 13696183259860 25335234661003 2
...

output:

53862492918
841550942082358
6318584331
11841747960898
7828131389582
980289764725
3145475463136418
4731285223548
7849116646764
6837627215249

result:

ok 10 lines

Test #19:

score: 5
Accepted
time: 217ms
memory: 3784kb

input:

10
43 5307034326326 7803963043338 2
33 5850130680 3566442328 2
47 81657611817194 17000720721223 2
28 110167317 18378160 1
36 64827623462 45249884950 1
43 2051110746728 6599647795014 1
31 518728699 480400606 1
39 165199827367 102440287723 2
48 40387581261144 270693373523553 1
30 903141702 529064835 2

output:

1122264909136
1963338708
24614645583109
257090932
220155016794
17301517083437
1998258559
66632466266
622161909569339
177859190

result:

ok 10 lines

Test #20:

score: 5
Accepted
time: 407ms
memory: 3776kb

input:

10
38 198588361301 232393133418 2
50 294565132478442 33791137273892 2
30 55881561 803651952 1
30 7371413 352844288 1
44 13614142901279 4285451502068 2
32 2005712628 2002619703 2
43 1025227881206 5922280820151 2
32 3094431796 1282443544 1
36 3141317430 5174015033 2
36 4013764674 39723823024 2

output:

29766440219
81750751735045
1719066994
720431377
4293637062674
992209858
1732346307186
8753750652
2087292545
10875543657

result:

ok 10 lines