QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#21438#2813. WeirdtreeQingyu100 ✓828ms42496kbC++203.6kb2022-03-05 02:15:082022-05-08 03:27:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 03:27:56]
  • 评测
  • 测评结果:100
  • 用时:828ms
  • 内存:42496kb
  • [2022-03-05 02:15:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

constexpr int inf = 1e9 + 100, maxn = 1 << 20;

struct element {
    long long sum;
    int max, max2, nr;
};

element mk_element(int x) { return element{x, x, -inf, 1}; }

constexpr element zero{0, -inf, -inf, 0};

element operator+(element a, element b) {
    return a.max == b.max
               ? element{a.sum + b.sum, a.max, max(a.max2, b.max2), a.nr + b.nr}
           : a.max > b.max
               ? element{a.sum + b.sum, a.max, max(a.max2, b.max), a.nr}
               : element{a.sum + b.sum, b.max, max(a.max, b.max2), b.nr};
}

element operator*(int x, element a) {
    assert(x > a.max2);
    return element{a.sum - (long long)a.nr * max(a.max - x, 0), min(a.max, x),
                   a.max2, a.nr};
}

int lazy[maxn];
element buf[2 * maxn];

void apply(int i, int x) {
    if (i >= maxn)
        buf[i] = mk_element(min(buf[i].max, x));
    else if (x > buf[i].max2 && x < lazy[i]) {
        lazy[i] = x;
        buf[i] = x * buf[i];
    } else if (x <= buf[i].max2) {
        apply(2 * i, x);
        apply(2 * i + 1, x);
        lazy[i] = inf;
        buf[i] = buf[2 * i] + buf[2 * i + 1];
    }
}

void prop(int i) {
    if (i < maxn) {
        apply(2 * i, lazy[i]);
        apply(2 * i + 1, lazy[i]);
        lazy[i] = inf;
    }
}

void up(int x) {
    while (x /= 2) buf[x] = lazy[x] * (buf[2 * x] + buf[2 * x + 1]);
}

void down(int x) {
    for (int i = __builtin_ctz(maxn); i > 0; --i)
        if (x >> i) prop(x >> i);
}

element query(int st, int dr) {
    down(st += maxn);
    down((dr += maxn) - 1);

    element ret = zero;
    for (; st < dr; st /= 2, dr /= 2) {
        if (st % 2) ret = ret + buf[st++];
        if (dr % 2) ret = ret + buf[--dr];
    }

    return ret;
}

void update(int st, int dr, int x) {
    down(st += maxn);
    down((dr += maxn) - 1);

    const int st0 = st, dr0 = dr;
    for (; st < dr; st /= 2, dr /= 2) {
        if (st % 2) apply(st++, x);
        if (dr % 2) apply(--dr, x);
    }

    up(st0);
    up(dr0 - 1);
}

int cbin(int st, int dr, int k) {
    auto t = query(st, dr);
    int k_ = t.nr - k, x = -1;

    auto upd = [&](int& k, int& k_, int i) {
        if (buf[i].max < t.max) return;
        if (k <= buf[i].nr) {
            x = i;
            k_ = buf[i].nr - k;
        } else
            k -= buf[i].nr;
    };

    for (st += maxn, dr += maxn; st < dr && x == -1; st /= 2, dr /= 2) {
        if (st % 2) upd(k, k_, st++);
        if (x == -1 && dr % 2) upd(k_, k, --dr);
    }

    while (x < maxn) {
        prop(x);
        x *= 2;
        if (buf[x].max < t.max)
            ++x;
        else if (buf[x].nr <= k)
            k -= buf[x++].nr;
    }

    if (k) ++x;

    return x - maxn;
}

void initialise(int n, int q, int h[]) {
    for (int i = 0; i < n; ++i) buf[i + maxn] = mk_element(h[i + 1]);
    for (int i = maxn - 1; i > 0; --i) {
        buf[i] = buf[2 * i] + buf[2 * i + 1];
        lazy[i] = inf;
    }
}

void cut(int l, int r, int k) {
    --l;
    while (k) {
        auto t = query(l, r);
        long long ops = (long long)(t.max - t.max2) * t.nr;
        if (ops <= k) {
            k -= ops;
            update(l, r, max(t.max2, 0));
        } else {
            int i = cbin(l, r, k % t.nr);
            update(l, i, max(t.max - k / t.nr - 1, 0));
            update(i, r, max(t.max - k / t.nr, 0));
            k = 0;
        }
    }
}

void magic(int i, int x) {
    down(i += maxn - 1);
    buf[i] = mk_element(x);
    up(i);
}

long long inspect(int l, int r) {
    auto t = query(l - 1, r);
    return t.sum;
}

詳細信息

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 13ms
memory: 34336kb

input:

966 1000
188363740 589476690 819684757 475179567 162289921 733331939 680003760 423847214 703730312 291752235 351463201 937522268 64588573 399012809 272561165 599780539 83270822 164102043 624995073 120374612 678210514 488108346 941579981 767236037 850406512 515467244 934426708 262361378 733612602 464...

output:

99386228771
285701011099
93632056850
281989163332
303817076569
20937894906
73151349399
132107688407
338284462998
24844890982
140888959978
170036512953
50814147522
97561625746
50275796014
55324327797
84580391349
51460901595
55077488581
213665989229
125662359971
96527688937
185212163367
373053648283
1...

result:

ok 344 lines

Test #2:

score: 0
Accepted
time: 22ms
memory: 34276kb

input:

901 1000
999589980 999214195 999743157 999126103 999286490 999267652 999519169 999294650 999667967 999980692 999941414 999668285 999190350 999451283 999145313 999185533 999557613 999043532 999834626 999040010 999897756 999877438 999216017 999586447 999943453 999368148 999692333 999719422 999849610 9...

output:

727634026462
258879131564
17989489017
135928706207
67155102578
334018096039
127934457359
28983788574
35979560747
407981705803
226978163582
252064441115
298035176042
475048150791
512283271171
215983094355
201341449542
43978687370
115133093457
325431689223
435245551509
28984946891
370804457448
1993427...

result:

ok 332 lines

Subtask #2:

score: 8
Accepted

Dependency #1:

100%
Accepted

Test #3:

score: 8
Accepted
time: 138ms
memory: 36980kb

input:

76150 80000
32029657 907857671 760489308 343887940 278226100 168470291 666158587 51251848 303560289 48411978 195584368 46479451 450233214 178362154 115287057 2938850 803717765 968392166 589034650 387534904 77112288 274256234 356840208 60923173 20797864 653643065 960669563 87025676 817522413 93024418...

output:

8220673678337
5971812049042
5242180957615
18711270761608
4512023121457
3137940370252
2563372483105
16476894579540
3810443569280
1752428600492
1277175092759
20184685804489
6170121667098
2671447647025
1307768277360
1171283123140
27506565529812
30664548514130
6755336989583
6736303909111
18622288366634
...

result:

ok 26917 lines

Test #4:

score: 0
Accepted
time: 134ms
memory: 37092kb

input:

74881 80000
999253788 999537237 999938023 999795613 999757608 999870879 999481582 999656236 999836358 999150683 999204145 999227254 999710240 999079025 999693342 999022977 999591405 999677201 999885066 999600228 999064530 999935628 999500310 999306968 999214870 999081235 999627217 999956727 99977794...

output:

54774696496748
42081439967265
17906018025059
1452284489789
34902518420002
52741883167138
8947948612098
28334365276474
43490239641264
37810635150696
31233626512118
43150921158245
15000326330951
2236880854586
17333035338161
28615408426074
1666174151668
27014951042332
55954804298660
894544648946
791510...

result:

ok 26864 lines

Subtask #3:

score: 8
Accepted

Test #5:

score: 8
Accepted
time: 20ms
memory: 34332kb

input:

937 1000
631216009 869613152 930472391 565464603 615860285 225788550 621532305 671044759 686011029 102483970 507799388 976017264 586239272 91471532 773404833 981261100 664781538 691746892 973047425 562711051 792865846 686480962 800771605 626015452 783329411 478894142 826983440 279108379 994766235 23...

output:

95606780168
457544848107
219664209531
231993445048
45093491390
212169943157
83594534601
87905941038
223049678373
219701120342
295206252594
120729585708
64510892813
210532163896
136112712054
371659611300
241511241359
114738069772
145079327633
108747456211
45224615812
42688643438
58295841604
182341668...

result:

ok 498 lines

Test #6:

score: 0
Accepted
time: 4ms
memory: 33988kb

input:

949 1000
999519718 999902943 999447920 999244333 999753736 999625525 999510644 999607278 999509183 999759464 999564254 999108564 999853733 999707294 999865603 999627938 999347514 999515367 999921660 999522368 999393937 999140755 999635541 999597063 999820316 999997036 999992932 999238119 999710671 9...

output:

478759193496
406432955383
572302351013
128835646103
77878397723
83956747116
56720046619
299058698094
868709108993
391237811293
189371302068
313614744353
596294850995
400899457787
351325190365
311433509970
943716802832
123103973771
344804316129
630751964778
579924574447
212913952051
201399913874
2598...

result:

ok 483 lines

Subtask #4:

score: 19
Accepted

Dependency #3:

100%
Accepted

Test #7:

score: 19
Accepted
time: 828ms
memory: 42256kb

input:

291883 300000
999936359 999157313 999230727 999238424 999882413 999896575 999978673 999337460 999548359 999811399 999390996 999497270 999931954 999879764 999443247 999606539 999476595 999102142 999200126 999296050 999318910 999115682 999722810 999085364 999476959 999731164 999921603 999818148 999348...

output:

24536675961253
36591698068600
130386794855060
84743638049390
218486807093766
107524207349810
199351358664253
137359344402974
105331373435581
18876571248355
41092500948440
74670722097761
71088471276529
100594671979121
38499764539908
276812577673768
65477272208413
35744128665834
72780585948501
1887226...

result:

ok 150067 lines

Test #8:

score: 0
Accepted
time: 750ms
memory: 42496kb

input:

298421 300000
169715272 368595215 340747188 786989761 913919345 636734809 242701368 733529927 153050197 33586227 111486783 747966776 934605105 10454181 735917976 658528906 28107953 618400502 44928250 568766281 123016186 395385737 899472863 239650692 356357808 816183954 617044296 452526489 135762157 ...

output:

106116327568210
94060268569708
2544943578742
27776574904904
9331528676129
54219779763576
20499459580956
57359068915473
96490181588073
54891379960242
29689116825163
31490397765151
48141493167364
48909212870174
25115276800333
84908121966770
26685319630825
7915603819888
48035190683493
10803702874511
21...

result:

ok 150518 lines

Test #9:

score: 0
Accepted
time: 805ms
memory: 42132kb

input:

286025 300000
999711316 999660706 999943096 999583321 999899686 999082295 999482116 999471529 999085521 999603881 999337749 999436831 999413801 999685361 999653331 999085897 999165725 999851806 999999677 999104231 999395614 999068227 999457259 999350592 999648087 999903220 999100008 999571000 999340...

output:

116130865065926
207280212957322
30950511546169
42902491683111
73178371041278
4340851343103
206847455763723
121531101685515
7912012851207
212840506962457
45054380703330
122173809284371
43545207052698
18682644802810
129490164883177
214726446094707
5869012442120
104190805824392
30461763985637
878290528...

result:

ok 149964 lines

Test #10:

score: 0
Accepted
time: 726ms
memory: 42204kb

input:

283159 300000
15407419 876189517 354059865 780053962 760396424 559303333 530173988 26997667 955519468 10973601 71685515 862885534 893295623 612644965 561588686 899623384 854679157 195710565 562304694 625278750 948149233 110279791 681081353 588034590 597372725 489857470 248820678 583210763 193823954 ...

output:

38022228721147
90722857833280
16856006708929
38888326995127
39064716533580
122722469052992
11740153286471
112270201673334
61116773171632
2291013146297
31929916825237
25646419838191
84900021402901
4551400552538
41341593902394
39946709602849
8783322100491
107284168788779
10374370366095
35206160514452
...

result:

ok 149860 lines

Subtask #5:

score: 10
Accepted

Test #11:

score: 10
Accepted
time: 379ms
memory: 41916kb

input:

279629 300000
864485544 147664426 873456004 602824795 902744016 20056943 260905686 609162276 241739883 338354289 437560714 444081255 584613844 200551305 963158452 282143442 169245526 10832409 265203076 576549337 275863148 94296798 887754059 15388512 25015579 800125936 979301246 68177101 30414420 446...

output:

139687223836955
139687172189279
139687251986142
139689123094384
139687693724295
139686994965044
139687352203414
139687352203414
139687379315277
139687379315276
139687379315276
139687287097921
139687287097921
139687287097921
139686797223823
139687622479427
139687537401529
139686761547581
139686761547...

result:

ok 99960 lines

Test #12:

score: 0
Accepted
time: 407ms
memory: 42264kb

input:

292243 300000
999290184 999603659 999611658 999334055 999800340 999202185 999135551 999612679 999074897 999888074 999473571 999291036 999839879 999334061 999530118 999558098 999150142 999727122 999419061 999963329 999992589 999423970 999278157 999856127 999768771 999533439 999428904 999172715 999012...

output:

292096581253875
292096581253875
292096138583191
292096138583191
292095265079347
292095265079347
292093590147387
292093385878483
292093276479426
292092877088665
292092877088665
292091889474064
292091889474064
292090906485682
292090906485680
292089381571892
292088600421851
292088600421850
292088600421...

result:

ok 99978 lines

Subtask #6:

score: 21
Accepted

Dependency #2:

100%
Accepted

Test #13:

score: 21
Accepted
time: 141ms
memory: 37184kb

input:

75845 80000
352335116 294504238 140746753 575637120 646370926 542454689 27511403 301851750 630047304 23922121 851703710 78428089 893692116 551981613 570170070 185553382 779494503 189901721 875572581 474024185 650102856 231626421 911326808 571881208 28910661 283637582 184021292 667581795 484271701 54...

output:

5142696678393
24479580615568
13952637881087
26984039375217
751437914074
7537468119244
21666538986653
15915350186518
7117291594288
9090946248649
19273685570584
12791450462938
4692202112321
35268742908920
23342859579852
22579508734308
3294699560846
6358126863701
18196836919713
12439582830160
138348857...

result:

ok 26814 lines

Test #14:

score: 0
Accepted
time: 135ms
memory: 37028kb

input:

73833 80000
999727358 999256844 999900994 999626372 999165464 999696323 999650044 999854547 999970302 999307975 999479027 999411551 999613365 999444397 999995305 999784245 999473731 999013781 999238557 999141711 999607756 999518504 999138140 999164504 999785896 999377579 999695175 999359164 99911974...

output:

5578209416126
45886163956150
5510247927505
14081962869726
50492633413842
5545306029384
895546178530
8009858450669
11186482370341
16374849732418
1386955714222
29488803889616
15956572039354
23840682041353
11921871983716
9588530425402
22454203414397
20280931115941
18745991038587
30588638496295
19827373...

result:

ok 26598 lines

Test #15:

score: 0
Accepted
time: 133ms
memory: 37476kb

input:

73311 80000
927807283 596499348 348238752 889935758 499460629 70815138 901992795 75868092 767995240 865721951 599732156 981041009 113960742 911458340 757630049 631221329 753379418 81377393 521360847 323413124 736982803 360322812 559939247 845124005 742434072 961823298 613455280 395672395 227913172 1...

output:

13379964835974
27103450916741
23798322660481
12037033498213
7136932328270
20758957756797
21121771369365
4772305004343
11741890704491
4356281632597
18248457696334
549648244204
3385939405187
5064418489962
17292234542811
24785086228350
26066681166940
3995295453189
3705173783507
6664624605928
1813776403...

result:

ok 26672 lines

Test #16:

score: 0
Accepted
time: 138ms
memory: 37508kb

input:

78391 80000
999862439 999429519 999585474 999265826 999904053 999095451 999650845 999541249 999021032 999059602 999684802 999540975 999922325 999081906 999636838 999921811 999220984 999071332 999584344 999794792 999413923 999113861 999891685 999142721 999068879 999093119 999536444 999677706 99916444...

output:

3333358046634
29771008733569
38080861369017
5803664866739
40134838317488
28283749233269
39878933570377
64974853280840
387795898306
68070100775534
42434117576869
46131627590015
8286431268568
1480260556724
38507887037839
54500845312399
17818541882019
56860576675893
54519989405214
28188806426480
119989...

result:

ok 26634 lines

Test #17:

score: 0
Accepted
time: 129ms
memory: 36996kb

input:

79682 80000
501363026 865434211 881520873 229475943 842073143 603255306 323297751 985458158 772012806 821760008 607969463 924977746 317547461 195660242 672694903 710448293 149272430 516772359 903331433 350637719 668315332 526431584 160754873 379820057 182585126 3938017 495365972 730586894 323855397 ...

output:

24050986067219
7227872143259
13825751379404
6289336391113
13809387198771
38724222913278
11646390668882
5022007537972
11735219346435
32910034945530
18503472255634
4084935431637
7851033775434
3628990117411
17378703922888
988614710820
8884547392312
26589204521592
15022544010437
18175301782916
282232614...

result:

ok 26605 lines

Test #18:

score: 0
Accepted
time: 173ms
memory: 37248kb

input:

80000 80000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10...

output:

79993600080000

result:

ok single line: '79993600080000'

Test #19:

score: 0
Accepted
time: 189ms
memory: 36716kb

input:

80000 80000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 10...

output:

79999999920001

result:

ok single line: '79999999920001'

Subtask #7:

score: 29
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #20:

score: 29
Accepted
time: 546ms
memory: 41808kb

input:

274590 300000
101623395 940715791 793543368 496086175 745885212 226080456 500533991 93753129 356840944 9894632 955331416 797128584 841006240 824888175 263336392 444144351 998540315 801869018 727179974 782398971 501979268 244013884 936936881 668662412 8433922 130255061 597098502 533310492 249339602 5...

output:

65995195801715
4740309627639
26257727205567
55049900392866
34397399237966
1088754210495
41433346204139
105989809888137
118277789914462
57555022242592
28820659981184
42092466790174
70274610615257
18175322957374
18008439463277
10231243675072
123903139169625
14037874440787
47753152755867
4161716426361
...

result:

ok 99850 lines

Test #21:

score: 0
Accepted
time: 593ms
memory: 42392kb

input:

295965 300000
999728167 999574528 999187102 999469360 999973036 999222218 999013321 999886191 999135851 999413863 999123353 999061027 999052763 999478557 999941588 999599342 999743714 999388640 999668104 999768131 999744033 999742827 999323707 999210149 999718310 999278274 999797710 999238374 999364...

output:

21814127617038
55228690647070
61332650804233
23839002156338
177329580485361
63009483364608
54750556407994
205615251992850
140548013755543
85641099253577
100462035852065
17624209602770
103008784662945
202079301411811
114364426029257
129540234449342
60075966354145
29914995228251
170901808146520
184643...

result:

ok 99928 lines

Test #22:

score: 0
Accepted
time: 566ms
memory: 42168kb

input:

291619 300000
276833017 43344173 968710452 337149819 62343981 536098106 607276643 416652576 52269395 296516046 37014017 465646431 873993856 295265387 891153374 649615471 164654818 201834392 866255200 209869122 50507854 48104968 504580391 129479841 815954622 928101042 715786719 739009188 375406489 83...

output:

116896238789741
71593710238553
33104598675097
42840743521855
34549036165682
56292533930505
57007427969187
38293237096953
21760940199516
25000584527659
70630446487595
26510741948914
67158826648440
35621420197871
32756597147384
42217579005576
25546178933693
11274036939143
248194039718
28760849981979
5...

result:

ok 100189 lines

Test #23:

score: 0
Accepted
time: 605ms
memory: 42140kb

input:

290756 300000
999477756 999947329 999109425 999682838 999734944 999160790 999858640 999976687 999930466 999709079 999748018 999032224 999515067 999717431 999937809 999041207 999295312 999585872 999027454 999437442 999012665 999302416 999997430 999222245 999845205 999188037 999573712 999467647 999529...

output:

149731081703065
149663110492973
283399177503946
275602004748503
108482578286665
110400357331758
142064801896190
83334085094738
74246464572676
38744547485446
209315417504422
237454946623727
40844934641135
39677885442181
77253953078556
171595317092388
97169651430225
23295281941612
186108956766804
1072...

result:

ok 99312 lines

Test #24:

score: 0
Accepted
time: 568ms
memory: 42060kb

input:

284440 300000
832511809 192171239 510217544 94320134 407994633 110838742 294352852 137819319 626163455 351941671 630551108 892110707 635769974 387114380 915653511 160857448 281233846 286850898 615808796 895331045 542694084 789999288 385823145 747013684 747145480 483529762 408932312 643103052 2178453...

output:

110268293359577
19481357076946
39638868818667
31120427709735
77913704679198
31238119740671
24732070067354
98359865046332
74032012362141
67293525561455
19636619775914
92261443828988
30657722040994
32915243421046
4935974229372
4750850153698
5463156944868
105440385362517
58041859876084
49395682655298
1...

result:

ok 99879 lines