QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#448261#6981. Fountaingiorgi123glm100 ✓523ms48592kbC++201.8kb2024-06-19 14:57:492024-06-19 14:57:49

Judging History

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

  • [2024-06-19 14:57:49]
  • 评测
  • 测评结果:100
  • 用时:523ms
  • 内存:48592kb
  • [2024-06-19 14:57:49]
  • 提交

answer

// All subtask (100point)

#include <iostream>
#include <vector>
#include <climits>
#include <stack>
using namespace std;

#define int long long

vector <pair <int, int> > v;
vector <vector <int> > gr;
vector <vector <int> > bin;
vector <vector <int> > binreq;

void dfs (int p, int par) {
    bin[p][0] = par;
    for (int i = 1; i < 17; i++)
        bin[p][i] = bin[bin[p][i - 1]][i - 1];
    
    binreq[p][0] = v[p].second;
    for (int i = 1; i < 17; i++)
        binreq[p][i] = binreq[p][i - 1] + binreq[bin[p][i - 1]][i - 1];
    
    for (int& e : gr[p])
        if (e != par)
            dfs (e, p);
}

signed main () {
    int n = 0, q = 0;
    cin >> n >> q;

    gr.resize (n + 2);
    bin.resize (n + 2, vector <int> (17));
    binreq.resize (n + 2, vector <int> (17));
    v.reserve (n + 2);
    v.resize (n + 1);
    for (int i = 1; i <= n; i++)
        cin >> v[i].first >> v[i].second;
    v.push_back ({INT_MAX, INT_MAX});

    vector <int> ri (n + 2, n + 1);
    {
        stack <int> s;
        for (int i = n + 1; i >= 1; i--) {
            while (s.size() && v[s.top()].first <= v[i].first)
                s.pop();
            
            if (s.size())
                ri[i] = s.top();
            
            s.push (i);
        }
    }

    for (int i = 1; i <= n; i++) {
        // parent = ri[i]
        gr[ri[i]].push_back (i);
        gr[i].push_back (ri[i]);
    }

    dfs (n + 1, 0);

    for (int i = 1; i <= q; i++) {
        int ind = 0, vi = 0;
        cin >> ind >> vi;

        for (int p = 16; p >= 0; p--)
            if (binreq[ind][p] < vi) {
                vi -= binreq[ind][p];
                ind = bin[ind][p];
            }
        
        if (ind == n + 1)
            cout << 0 << '\n';
        else
            cout << ind << '\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 30
Accepted

Test #1:

score: 30
Accepted
time: 0ms
memory: 3608kb

input:

10 20
1904 5
101 2
1107 1
1098 3
161 4
1042 9
1812 1
2751 2
680 1
842 7
5 9
9 1
5 3
9 1
5 14
3 2
3 1
4 4
5 1
3 1
7 1
3 2
2 4
8 2
3 1
3 2
6 10
2 4
9 1
9 1

output:

6
9
5
9
7
7
3
7
5
3
7
7
7
8
3
7
7
7
9
9

result:

ok 20 lines

Test #2:

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

input:

517 531
6889 136
3220 356
2609 378
1860 297
922 349
1784 404
2533 245
3177 429
3628 469
368 338
4793 466
895 218
1448 336
4120 205
701 450
3120 176
1902 312
982 252
1281 137
1843 482
2250 393
3022 238
3452 168
3464 70
296 334
544 419
236 163
900 257
4048 195
4749 19
5394 176
6048 262
6821 306
4159 4...

output:

79
234
499
257
121
28
261
168
479
264
265
315
449
260
422
404
234
428
438
446
264
512
166
187
264
492
450
439
261
265
433
293
449
349
48
406
429
210
157
430
453
233
260
258
260
511
262
483
406
262
439
431
234
226
437
212
406
396
243
233
319
243
129
263
450
444
493
437
261
305
204
243
427
409
335
438...

result:

ok 531 lines

Test #3:

score: 0
Accepted
time: 2ms
memory: 4080kb

input:

705 878
10382 3
8785 487
157 113
5386 635
2204 587
128 305
597 624
1362 649
500 551
1292 307
2125 589
4126 451
4051 670
139 700
244 107
816 504
1235 120
1839 63
510 47
482 583
218 506
1447 540
2176 655
777 187
1540 425
629 441
661 321
2945 604
3823 693
3975 14
4463 650
1326 627
886 432
832 695
1273 ...

output:

182
228
386
304
482
595
50
500
226
343
36
96
436
312
97
252
312
522
303
474
314
520
313
384
282
499
490
578
154
477
312
102
384
341
277
522
400
305
666
253
312
386
477
246
503
512
29
102
266
309
477
522
318
145
252
627
519
522
44
458
519
31
95
124
145
310
313
138
443
504
567
140
141
164
154
494
304
...

result:

ok 878 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 4188kb

input:

977 1370
318 971
436 123
6960 130
5909 809
398 289
1119 401
5876 600
5621 10
694 538
3631 588
739 53
3266 734
282 625
3199 970
414 658
1079 104
1642 438
1847 927
2615 627
2714 394
3114 855
3551 923
4631 498
5526 806
5849 458
794 899
1433 555
2330 818
911 278
207 154
4935 578
972 271
928 732
1806 185...

output:

728
724
187
365
451
918
711
285
285
904
544
544
115
725
951
272
281
965
452
409
366
64
963
294
918
787
550
549
722
727
708
210
124
295
866
608
725
918
919
780
722
330
752
531
868
825
552
261
676
435
729
747
425
749
548
285
60
728
278
149
546
277
646
712
362
548
493
908
877
221
545
916
776
634
648
72...

result:

ok 1370 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 4048kb

input:

1000 2000
785 139
1285 64
1977 229
2466 398
2739 310
2891 583
3083 444
3183 421
3845 813
3846 809
4543 495
4671 111
5645 623
6459 884
7268 842
7907 436
8811 208
8923 313
9053 784
9940 765
10624 156
11430 272
12068 429
12825 428
13028 481
13231 700
14169 487
14970 223
15482 356
16258 811
16662 681
16...

output:

740
420
761
885
409
717
726
830
386
356
189
670
639
657
585
955
835
616
897
689
707
535
109
830
597
571
994
671
446
616
899
770
192
74
418
984
932
457
832
880
509
169
845
543
243
367
736
188
844
891
475
893
327
821
916
939
479
727
665
844
988
283
687
712
453
733
895
645
815
912
734
635
460
810
716
8...

result:

ok 2000 lines

Test #6:

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

input:

1000 2000
114 213
174440 737
172544 695
172522 726
2299 179
1841 127
298 471
1160 155
623 398
688 75
958 119
1071 102
1806 989
2273 555
171804 861
171143 176
450 820
169440 917
166761 631
130 355
513 83
166676 954
419 622
166409 651
165582 652
12 984
598 772
1045 769
477 184
1912 87
164728 736
16401...

output:

956
898
549
923
696
999
964
927
654
764
715
866
612
839
406
879
563
579
785
690
726
909
901
889
515
930
533
987
612
585
814
912
915
673
935
137
915
641
917
915
903
888
543
931
727
815
688
464
777
674
691
720
854
698
460
691
921
912
899
787
894
700
869
389
852
814
920
996
999
785
632
705
934
566
979
...

result:

ok 2000 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 4016kb

input:

1000 2000
6078 785
6057 98
6021 432
6012 269
5952 240
5905 86
5863 447
5806 293
5708 555
5662 613
5584 428
5555 276
5551 193
5499 910
5424 248
5419 492
5332 490
5300 588
5299 116
5271 725
5190 181
5143 635
5099 999
5033 243
4974 768
4879 970
4781 697
4698 403
4696 133
4623 210
4525 250
4458 269
4397...

output:

627
25
173
216
782
504
288
605
714
196
875
138
196
998
389
377
196
146
196
584
196
465
245
326
196
5
916
722
543
196
444
243
226
843
41
495
708
796
671
686
897
223
782
541
584
891
872
767
636
112
215
782
584
425
107
320
389
188
520
196
637
792
107
308
465
782
279
196
423
263
137
52
196
251
808
306
4...

result:

ok 2000 lines

Subtask #2:

score: 30
Accepted

Test #8:

score: 30
Accepted
time: 287ms
memory: 46312kb

input:

95174 123506
841 399
1767 274
2047 323
2384 957
2786 959
3140 526
3619 601
3752 714
3784 811
3979 898
3987 919
4617 956
4794 39
5404 321
5968 893
6432 939
6979 892
7540 797
8117 183
8944 941
9222 56
9491 520
10394 42
10483 171
10521 244
10777 621
11433 451
12080 23
12219 727
12939 799
13305 71
14284...

output:

66621
64394
70636
60750
83310
42863
39165
56768
56462
91360
50877
92763
82900
19848
75309
53586
80758
49315
85573
45202
92528
35466
30994
78182
65359
61697
31403
30887
32775
76562
17331
75182
21644
77339
75595
42327
19056
19487
79874
45553
22113
67607
58737
67966
87691
15474
88350
89180
73759
47713
...

result:

ok 123506 lines

Test #9:

score: 0
Accepted
time: 326ms
memory: 42836kb

input:

87468 143732
293 882
813 2
1369 533
1760 833
2036 867
2545 223
3230 230
3782 279
4714 35
5390 261
5410 152
5715 853
5938 203
6301 363
6715 322
7228 979
8202 996
8411 204
8863 539
9672 94
9682 733
10630 96
11228 369
11559 216
11833 759
12723 460
12794 655
12867 51
13452 323
13552 942
13928 385
14157 ...

output:

17109
69440
26197
54438
44823
84174
72118
22527
87212
62527
58257
56440
35803
81614
49418
49735
57020
11375
55510
82421
86930
37724
81275
47475
56080
9622
22649
45299
61786
73131
39935
47156
82448
31254
66898
86012
47196
67232
41095
44740
35007
56557
19806
56683
45040
21324
38319
25644
33668
37648
4...

result:

ok 143732 lines

Subtask #3:

score: 40
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #10:

score: 40
Accepted
time: 0ms
memory: 3948kb

input:

1001 2001
50 143
1004 362
1892 204
2307 561
3704 510
593 815
268 566
2686 447
1608 590
752 532
1593 137
969 713
479 356
1960 109
450 783
440 252
251 250
278 148
2606 582
636 572
216 8
86 51
3639 840
4125 129
3955 912
1798 362
800 42
718 761
1748 265
132 645
967 146
892 759
2419 358
728 702
3273 671
...

output:

536
249
41
774
110
170
582
35
421
70
283
582
466
437
64
167
656
537
266
724
138
239
637
990
567
723
774
201
628
471
779
74
697
997
504
398
838
554
605
962
411
582
266
638
797
525
537
607
135
863
645
53
64
613
283
110
370
878
53
745
331
109
902
399
167
465
805
413
750
774
110
537
283
220
283
664
67
5...

result:

ok 2001 lines

Test #11:

score: 0
Accepted
time: 131ms
memory: 26312kb

input:

55460 91385
1560 891
1532 508
629 835
1525 596
5785847 87
5785845 319
1908 169
1889 702
910 668
1859 578
5785789 432
303 626
748 980
5785294 583
5780704 34
5780216 531
687 364
5778213 136
5777219 16
5777216 153
5775201 880
666 506
5774459 348
293 87
210 138
617 820
395 907
1081 816
5773815 628
57737...

output:

45660
34633
51418
49566
48505
36500
48126
51510
48682
51048
43841
42212
51779
47914
27815
53623
48141
54426
54784
46597
38207
40058
54651
42161
48843
45616
50359
38887
42737
40987
44371
39299
45938
49238
51400
48233
42676
48294
52066
55050
47615
50806
49877
42981
39229
40620
51302
39526
35516
48080
...

result:

ok 91385 lines

Test #12:

score: 0
Accepted
time: 523ms
memory: 48592kb

input:

100000 200000
948 751
1335 344
2046 115
2579 458
3408 113
3610 876
4054 396
4656 958
4908 976
5226 457
6076 190
6745 623
6956 683
7727 113
8528 788
9328 972
10171 700
10824 419
11557 179
11926 747
12021 315
12739 429
13507 910
13871 798
14394 236
15335 774
15689 844
15957 696
16374 403
16518 362
167...

output:

91186
73769
94744
91300
84339
83297
42867
65580
30343
9541
81206
82994
29539
51390
26650
27122
22534
50515
80039
54980
49872
78803
23646
83184
83682
74225
49516
99700
1230
30508
64703
14931
91492
34458
88594
98721
60635
22047
76986
76322
74937
77581
88592
24270
52467
14297
99802
57164
83210
40464
42...

result:

ok 200000 lines

Test #13:

score: 0
Accepted
time: 370ms
memory: 44988kb

input:

100000 200000
9521692 571
130 967
9521612 968
9516151 223
10162 731
997 993
9331 855
78 635
863 335
1840 705
2002 173
9253 444
9046 154
59 368
104 913
7227 53
818 576
1670 397
141 513
3613 311
2925 820
1076 991
850 475
1063 875
2045 880
2882 837
3546 928
3596 672
4560 640
531 560
5187 708
382 210
54...

output:

80251
95905
81754
77535
94268
64132
99397
62457
64339
57784
94235
94267
94153
79714
96282
93200
84813
87259
89368
58492
71216
77635
91332
87252
65587
99018
59533
87027
82818
52438
65502
97917
79720
98642
80000
52738
73495
77193
90660
86153
67731
76660
92571
79498
77245
83556
99577
51729
58937
98440
...

result:

ok 200000 lines

Test #14:

score: 0
Accepted
time: 231ms
memory: 44260kb

input:

100000 200000
992 952
1451 75
15001 103
853 829
322 469
5857 973
370 694
3389 351
3336 816
2270 332
52 147
2063 793
1426 28
537 558
1202 999
1361 693
1443 346
404 996
729 41
2013 773
2032 727
2221 198
808 838
2682 320
69 902
1051 713
634 433
1042 854
3007 663
445 125
1962 603
1377 614
118 199
1345 5...

output:

27678
83815
45446
7313
19440
38141
50799
87103
11214
64562
48468
2575
18505
90092
9523
58508
89718
91778
59735
12764
14643
65090
77799
52697
33881
35637
41745
38496
27158
57886
64562
76850
77295
16750
97770
42603
72947
42722
37243
66827
5035
96294
46178
73873
70971
47893
62513
13707
86832
48899
1154...

result:

ok 200000 lines

Test #15:

score: 0
Accepted
time: 220ms
memory: 44756kb

input:

100000 200000
100000000 837
99999204 111
99998287 255
99997355 609
99997034 84
99996814 341
99995988 679
99995390 808
99994512 497
99993648 624
99992875 705
99991968 88
99991792 58
99991523 236
99990734 202
99990602 181
99990025 849
99989587 555
99988811 163
99988806 152
99988499 545
99987567 644
99...

output:

99906
99906
99903
65310
53304
57350
69694
75490
99906
54352
41398
99902
54088
51475
92816
99529
52022
77327
48911
99903
58545
36011
12664
99905
99902
99906
99905
99906
95887
44058
99906
99906
70038
99902
99902
99903
83075
39076
12464
58228
99906
99905
33001
78676
75057
99903
66172
99903
56519
99903
...

result:

ok 200000 lines