QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#448246#6981. Fountainnikaa123100 ✓84ms12576kbC++232.4kb2024-06-19 14:47:592024-06-19 14:47:59

Judging History

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

  • [2024-06-19 14:47:59]
  • 评测
  • 测评结果:100
  • 用时:84ms
  • 内存:12576kb
  • [2024-06-19 14:47:59]
  • 提交

answer

// #pragma GCC diagnostic warning "-std=c++11"
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pp pop_back
#define endl '\n'
#define ff first
#define ss second
#define stop exit(0)
#define sz(x) (int)x.size()
#define pause system("pause")
#define all(x) (x).begin(),(x).end()
#define deb(x) cout << #x << "-" << x  << endl
 
typedef char chr;
typedef string str;
typedef long long ll;
typedef vector <int> vii;
typedef pair <int,int> pii;
 
const long long INF = LLONG_MAX;
const int inf = INT_MAX;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int dx[] = {0,0,-1,1};
const int dy[] = {-1,1,0,0};
const double PI = 2 * acos(0.0);

const int N = 2e5 + 5;

int n,q;
int d[N],c[N];
pair <pii,int> b[N];
int cur,ans;
int pref[N],answer[N];
vii v;

inline void test_case () {  
    
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> d[i] >> c[i];
    }
    
    for (int i = 1; i <= q; i++) {
        cin >> b[i].ff.ff >> b[i].ff.ss;
        b[i].ss = i;
    }
    sort(b+1,b+1+q,greater<pair<pii,int>>());
    cur = 1;
    v.pb(1);
    for (int i = n; i >= 1; i--) {
        while (sz(v) > 1 && d[i] >= d[v.back()]) {
            v.pp();
        }
        v.pb(i);
        pref[sz(v)-1] = pref[sz(v)-2] + c[i];
        while (i == b[cur].ff.ff) {
            ans = INF;
            int l = 1; int r = sz(v)-1;
            while (l <= r) {
                int mid = (l+r)/2;
                if (pref[sz(v)-1] - pref[mid-1] >= b[cur].ff.ss) {
                    ans = v[mid];
                    l = mid + 1;
                } else {
                    r = mid - 1;
                }
            }
            answer[b[cur].ss] = ans;
            cur++;
        }
    }
    for (int i = 1; i <= q; i++) {
        if (answer[i] == INF) {
            cout << 0 << endl;
            continue;
        }
        cout << answer[i] << endl;
    }
    

}
 
signed main () {
 
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int T = 1;
    // cin >> T;
    while(T--) {
        test_case();
    }
    
    return 0;
 
}

詳細信息

Subtask #1:

score: 30
Accepted

Test #1:

score: 30
Accepted
time: 1ms
memory: 3724kb

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: 30
Accepted
time: 1ms
memory: 3668kb

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: 30
Accepted
time: 1ms
memory: 3612kb

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: 30
Accepted
time: 1ms
memory: 3720kb

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: 30
Accepted
time: 1ms
memory: 3832kb

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: 30
Accepted
time: 1ms
memory: 3720kb

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: 30
Accepted
time: 1ms
memory: 3716kb

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: 39ms
memory: 10164kb

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: 30
Accepted
time: 60ms
memory: 10824kb

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: 1ms
memory: 3752kb

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: 40
Accepted
time: 29ms
memory: 7592kb

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: 40
Accepted
time: 84ms
memory: 12576kb

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: 40
Accepted
time: 60ms
memory: 11716kb

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: 40
Accepted
time: 57ms
memory: 11468kb

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: 40
Accepted
time: 51ms
memory: 11448kb

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