QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#382266#4947. 混合果汁bachbeo2007100 ✓309ms66988kbC++233.7kb2024-04-08 10:02:502024-04-08 10:02:51

Judging History

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

  • [2024-04-08 10:02:51]
  • 评测
  • 测评结果:100
  • 用时:309ms
  • 内存:66988kb
  • [2024-04-08 10:02:50]
  • 提交

answer

// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int mod2=1e9+7;
const int maxn=100005;
const int bl=650;
const int maxs=650;
const int maxm=200005;
const int maxq=500005;
const int maxl=20;
const int maxa=100000;
int power(int a,int n){
    int res=1;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;n>>=1;
    }
    return res;
}
namespace Segtree{
    int tree[4*maxn],num[4*maxn];
    void update(int l,int r,int id,int p,int val){
        if(l==r){
            tree[id]+=val;
            num[id]+=p*val;
            return;
        }
        int mid=(l+r)>>1;
        if(p<=mid) update(l,mid,id<<1,p,val);
        else update(mid+1,r,id<<1|1,p,val);
        tree[id]=tree[id<<1]+tree[id<<1|1];
        num[id]=num[id<<1]+num[id<<1|1];
    }
    int query(int l,int r,int id,int lim){
        if(l==r) return lim*l;
        int mid=(l+r)>>1;
        if(lim<=tree[id<<1]) return query(l,mid,id<<1,lim);
        else return num[id<<1]+query(mid+1,r,id<<1|1,lim-tree[id<<1]);
    }
}
struct que{int g,L,id;};
int n,m,ans[maxn];
vector<pii> a[maxn];
vector<que> query[maxn];
void dnc(int l,int r){
    int mid=(l+r)>>1,mid1=(l+mid-1)>>1,mid2=(mid+1+r)>>1;
    for(auto x:query[mid]){
        if(x.L<=Segtree::tree[1] && Segtree::query(1,maxa,1,x.L)<=x.g){
            ans[x.id]=mid;
            if(mid<r) query[mid2].push_back(x);
        }
        else if(l<mid) query[mid1].push_back(x);
    }
    if(l<mid){
        for(int i=mid1;i<mid;i++){
            for(pii x:a[i]) Segtree::update(1,maxa,1,x.fi,x.se);
        }
        dnc(l,mid-1);
        for(int i=mid1;i<mid;i++){
            for(pii x:a[i]) Segtree::update(1,maxa,1,x.fi,-x.se);
        }
    }
    if(mid<r){
        for(int i=mid;i<mid2;i++){
            for(pii x:a[i]) Segtree::update(1,maxa,1,x.fi,-x.se);
        }
        dnc(mid+1,r);
        for(int i=mid;i<mid2;i++){
            for(pii x:a[i]) Segtree::update(1,maxa,1,x.fi,x.se);
        }
    }
}
void solve(){
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        int d,p,l;cin >> d >> p >> l;
        a[d].push_back({p,l});
    }
    for(int i=1;i<=m;i++){
        int g,L;cin >> g >> L;ans[i]=-1;
        query[maxa/2].push_back({g,L,i});
    }
    for(int i=maxa/2;i<=maxa;i++){
        for(pii x:a[i]) Segtree::update(1,maxa,1,x.fi,x.se);
    }
    dnc(1,maxa);
    for(int i=1;i<=m;i++) cout << ans[i] << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int test=1;//cin >> test;
    while(test--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 3ms
memory: 8024kb

input:

10 10
44894 45296 4296
96357 95394 34037
23283 23930 43005
43330 43000 38959
47744 48195 10266
27116 26946 81420
60433 60242 95603
31529 32036 81788
48404 48829 81712
77157 76571 51380
90171111 9412
1063760163 7125
1507224419 3799
667070329 949
1315536036 7388
854846064 8708
990959616 3410
59788892 ...

output:

-1
96357
96357
96357
96357
96357
96357
-1
96357
96357

result:

ok 10 numbers

Test #2:

score: 5
Accepted
time: 3ms
memory: 7896kb

input:

10 10
71203 70943 96030
2907 3366 43446
59057 58730 29943
20030 19971 5151
54659 54133 16206
61347 60820 58102
73802 73343 32955
49325 49519 51020
53790 53260 12493
60357 60341 33443
1039324449 4656
396371768 1370
1385376577 1519
1468730283 4687
1728094263 8256
124371528 7039
1505613387 3776
1556326...

output:

73802
73802
73802
73802
73802
2907
73802
73802
73802
20030

result:

ok 10 numbers

Test #3:

score: 5
Accepted
time: 3ms
memory: 9976kb

input:

10 10
84357 83668 41893
56186 56253 48151
26943 27631 23412
58381 58408 88250
58116 57651 69178
28461 28256 96445
80486 80295 1631
8221 8761 35636
6481 6525 77888
1954 2227 24475
1602937961 2278
1977095578 1844
596473909 4801
1449483215 2251
111122583 1909
1676272921 6864
757255225 1309
765268006 55...

output:

84357
84357
84357
84357
58116
84357
84357
84357
84357
84357

result:

ok 10 numbers

Test #4:

score: 5
Accepted
time: 3ms
memory: 12652kb

input:

500 500
97511 97491 87760
9461 10239 52855
94832 94531 16881
96733 95943 71346
61574 61071 22147
95578 94693 34784
87171 86345 70311
67121 67002 20252
59176 58790 43278
43556 43112 15506
98999 97920 23186
65677 65753 91043
98152 97786 55624
29880 30171 50326
88425 87521 63173
98803 97967 11869
67562...

output:

100000
98752
99591
98667
99591
3254
98999
100000
98667
99591
97778
100000
99591
36573
98667
97952
98162
98667
100000
99591
98667
98152
42477
98667
63135
98162
98752
13234
98667
92847
97778
99591
-1
45459
99591
98667
98152
100000
98162
98162
98152
67954
60591
98162
100000
100000
99591
99591
97778
268...

result:

ok 500 numbers

Test #5:

score: 5
Accepted
time: 3ms
memory: 11412kb

input:

500 500
23816 24039 79489
16015 16211 62265
30602 30332 3819
73433 72915 37538
68488 68009 28087
29806 29665 11466
536 1446 7663
84917 84485 89488
64562 64320 74063
26755 26882 97574
51437 51420 32679
12891 13137 17568
49432 49555 28691
79290 79043 94860
39095 38918 77711
25127 25774 66413
54844 544...

output:

97979
98309
98696
31128
99242
99107
99107
98309
97773
99107
99242
98696
28687
98309
38895
97773
98696
98696
97352
97352
35756
99242
99107
99242
98696
39453
54749
66559
98696
97676
44075
98309
98696
6383
97352
16480
99242
99107
32079
98696
98696
99242
99242
98309
99242
98309
97979
99242
97773
58889
9...

result:

ok 500 numbers

Test #6:

score: 5
Accepted
time: 6ms
memory: 11608kb

input:

500 500
50124 50588 71219
22568 23083 71674
66377 66033 90761
50132 49887 3730
75403 75046 34027
64037 63539 88153
13905 14547 45019
2710 2968 58721
69948 69850 4845
9954 10653 79637
3874 3821 42173
60109 59621 44097
712 1324 1757
28696 28914 39390
89768 89414 92248
51455 51580 20953
42126 42421 825...

output:

33149
97474
98362
42245
99887
99823
99823
99823
99887
99104
98362
99104
98860
97474
98362
99823
99823
93498
99823
99104
99104
52287
97474
99887
98860
99823
99887
99104
6745
77010
98118
98362
98118
99823
98118
98118
98362
99887
99823
99823
98118
99104
26530
99823
99823
99823
57963
98118
99823
98362
9...

result:

ok 500 numbers

Test #7:

score: 5
Accepted
time: 8ms
memory: 16964kb

input:

5000 5000
63279 63312 17082
75847 75069 76378
34262 33934 84230
88484 88323 86830
78860 78465 86999
31151 30976 26492
20589 20499 13695
61610 61209 43337
22639 23115 70239
51556 51538 70669
80097 79522 46919
33717 33813 7359
76356 76159 38293
53400 53448 11655
65102 64711 99517
14617 15033 48225
857...

output:

99410
38707
99768
99978
99978
99862
98231
98680
99410
98565
99504
99510
82864
99862
99960
99332
22974
98487
98744
98867
99206
15373
99973
98344
98433
39880
99601
99507
99206
99862
99813
99531
98628
99658
99510
99871
26708
99978
98424
99062
149
98930
46889
99923
98867
99978
98679
21612
99300
99431
45...

result:

ok 5000 numbers

Test #8:

score: 5
Accepted
time: 14ms
memory: 16864kb

input:

5000 5000
89587 88861 8812
82401 82041 85788
70036 69734 71168
65183 65295 53021
85775 85403 92940
65382 64849 3174
33958 33600 51051
79406 78692 12569
28025 28644 1020
34755 35308 52733
32535 33022 56413
80935 80197 33888
27637 27928 11359
2806 3319 56189
15772 16108 14051
40945 40839 2766
73051 72...

output:

99759
99569
98409
98468
99384
99384
77672
73589
99639
98581
99492
99844
99100
99817
99794
99363
99794
98815
99640
99966
98812
21643
98328
99405
9929
42516
99207
99327
99194
98812
99185
72194
42153
99048
99794
99242
99405
99255
99437
99013
15294
98943
30687
98576
60883
98746
99805
75853
98943
89748
9...

result:

ok 5000 numbers

Test #9:

score: 5
Accepted
time: 16ms
memory: 17688kb

input:

5000 5000
15892 16409 541
88954 88914 95197
5807 6535 58106
41883 42267 19213
92690 92341 98880
99613 98821 79860
47327 47701 88407
97202 97175 81805
33411 33174 31805
17954 18079 34796
84977 84422 65906
28149 28582 60417
78921 78697 84430
52216 52190 718
66445 66604 28589
67273 66646 57310
60332 60...

output:

99259
99896
97694
77683
99935
98723
97694
83185
99465
60656
98295
98471
99135
99463
98471
98376
99744
98612
25451
98702
98376
99729
97730
98106
99994
99935
99920
98142
99935
97730
460
3152
53053
98376
98925
99837
24956
98880
99607
99372
97730
99427
99969
99650
97837
98339
99388
97651
99405
97738
996...

result:

ok 5000 numbers

Test #10:

score: 5
Accepted
time: 163ms
memory: 62352kb

input:

100000 100000
42200 1 27746
92275 1 95508
34071 1 4602
41581 1 15081
45044 1 18582
92340 1 85409
99604 1 77335
4816 1 33840
23227 1 56542
60696 1 70815
25760 1 14994
80735 1 51037
38797 1 29184
62590 1 1153
75943 1 16859
37414 1 89590
75399 1 75367
41889 1 86946
30201 1 56744
57497 1 1622
47699 1 45...

output:

-1
98987
99947
99334
99039
99169
99897
99575
-1
99295
98328
98965
-1
99550
99305
98443
-1
99008
98323
98743
98476
-1
98255
98574
98986
-1
99123
-1
98713
99657
-1
99657
99867
99534
99481
98114
99095
-1
-1
99121
99832
98664
98683
99175
98825
99216
-1
98819
99724
99657
-1
98936
98439
99503
-1
98557
998...

result:

ok 100000 numbers

Test #11:

score: 5
Accepted
time: 159ms
memory: 62364kb

input:

100000 100000
7968 1 5547
21597 1 61890
43551 1 28126
81015 1 54731
12389 1 10333
52046 1 888
16887 1 4063
69669 1 69416
27076 1 48250
94118 1 79558
69148 1 9482
45952 1 74121
2260 1 75168
89551 1 9153
26536 1 72022
18513 1 20814
99132 1 43407
6004 1 3262
8405 1 52263
40165 1 25142
38974 1 6581
9379...

output:

98795
99750
99871
99200
99474
-1
-1
-1
99831
99758
99698
98670
99219
-1
99566
-1
-1
99375
99230
98365
98776
98186
99847
98443
-1
99766
98801
99603
98653
98807
99070
99725
-1
99827
99650
99371
99731
98812
98033
99962
98226
-1
99171
99182
99891
98391
99947
99974
98460
98182
98340
98332
98747
99586
997...

result:

ok 100000 numbers

Test #12:

score: 5
Accepted
time: 174ms
memory: 60336kb

input:

100000 100000
73740 1 83353
50923 1 28273
53031 1 51649
20445 1 94380
79738 1 2084
11753 1 16371
34174 1 30794
34518 1 4989
30926 1 39957
27537 1 88301
12532 1 3970
11169 1 97206
65727 1 21148
16507 1 17153
77134 1 27181
99615 1 52042
22862 1 11447
70124 1 19582
86613 1 47781
22834 1 48662
30249 1 6...

output:

98866
99658
-1
-1
99139
99953
98657
99401
98176
99473
98194
99117
98073
99782
-1
99623
98249
99793
98183
99038
99795
-1
99439
99650
98802
-1
99486
-1
98989
-1
99058
99317
-1
98190
98356
98885
99087
99503
99675
99806
99990
-1
98878
98296
-1
-1
99117
-1
99288
98061
98403
99233
98255
99757
-1
99067
-1
...

result:

ok 100000 numbers

Test #13:

score: 5
Accepted
time: 288ms
memory: 65152kb

input:

100000 100000
39507 39717 1
94659 94280 1
59879 59543 1
93838 93577 1
51461 51462 1
40565 40443 1
60959 61262 1
98462 98180 1
29190 29481 1
25153 25127 1
80713 80726 1
79490 78949 1
64818 64585 1
72183 71595 1
47149 47573 1
41051 40748 1
2229 2783 1
33661 33330 1
47327 47662 1
88486 87626 1
47016 47...

output:

99684
18222
99641
99770
99617
18473
99301
99419
99811
99664
18383
99004
99341
99581
99434
21580
99779
80703
53584
99138
99743
86374
99054
99508
99346
99086
99344
95038
99560
93017
99340
80502
99888
99591
99642
43528
99054
99173
34120
99090
99228
99968
99937
26809
40539
99196
33686
99156
99285
99549
...

result:

ok 100000 numbers

Test #14:

score: 5
Accepted
time: 285ms
memory: 65344kb

input:

100000 100000
5275 5538 1
61041 61110 1
99313 99044 1
85589 84957 1
68747 68856 1
76141 75726 1
94382 93415 1
92950 92388 1
92657 91806 1
33153 33553 1
61811 61327 1
47530 48009 1
43022 42959 1
95703 94871 1
23826 23764 1
56869 56813 1
20436 20633 1
52549 52416 1
30580 30463 1
43088 42983 1
99280 98...

output:

99205
99283
99818
99831
98549
99121
99413
99811
59062
99678
99478
99127
99801
82546
99859
99302
93487
57368
99425
38787
99765
99180
99972
99647
99686
99453
99843
99776
99374
23571
99717
99461
99899
99301
53028
99604
99721
99312
99629
99506
99801
99147
99468
99487
4387
99163
99802
30901
29436
99858
9...

result:

ok 100000 numbers

Test #15:

score: 5
Accepted
time: 287ms
memory: 64088kb

input:

100000 100000
84200 84282 1
80702 79927 1
6628 7347 1
15688 15873 1
89491 88670 1
78830 78445 1
34485 34619 1
46334 46836 1
8811 9395 1
82755 82864 1
19129 19629 1
89181 89162 1
96871 96167 1
43925 43485 1
75842 75153 1
35849 36331 1
82285 81414 1
95215 94338 1
30484 30283 1
88615 88490 1
1990 2232 ...

output:

44556
99325
80252
99448
99594
99977
35238
99980
99493
99351
82886
99857
99816
99414
99948
-1
87358
8946
34004
99561
99372
99030
99077
99670
99401
92038
99682
99594
99752
99354
9123
10905
99973
99178
99838
52352
46799
38089
99493
99130
99974
99282
7569
99715
99492
87504
99404
99681
64551
99568
99720
...

result:

ok 100000 numbers

Test #16:

score: 5
Accepted
time: 285ms
memory: 66988kb

input:

100000 100000
63122 62926 59954
360 645 55147
13947 14650 36061
45790 45788 44496
10232 10583 99860
81520 81164 83473
74592 73823 23432
99722 99285 58771
24969 24886 55130
32353 32175 29887
76450 75931 27284
30828 31415 11386
50715 50474 26579
92150 92098 57766
27853 27542 75723
14829 14850 84525
44...

output:

99920
99080
99623
99884
85818
99848
11115
42291
-1
84799
99853
42945
20115
99659
99396
98773
99061
98602
98557
98647
22154
98155
99851
99285
98546
97925
36335
99024
99889
7093
98174
98603
63901
99870
79605
99098
98498
98573
99846
99688
99906
99064
99903
99904
99100
20604
43213
35511
98573
78020
9947...

result:

ok 100000 numbers

Test #17:

score: 5
Accepted
time: 303ms
memory: 66844kb

input:

100000 100000
42044 42571 35143
20021 20462 83375
21266 21953 96879
75892 75704 43075
30976 31396 17677
84210 83883 13520
14695 15027 35496
53106 52733 66472
41127 41476 47481
81954 81486 76081
33767 34233 55764
72478 72568 90972
4560 4682 45783
40371 40711 91364
79869 79931 19332
93813 93368 48149
...

output:

99543
98819
99294
99069
99393
99802
38790
21431
98859
98880
98624
75920
62323
98467
99805
37301
99695
99127
98357
99927
99594
68354
98240
41468
99666
71822
99249
99053
99999
73217
57006
99136
79029
99305
78143
99824
99229
24497
99263
37923
98751
30579
99589
98367
75854
58429
61763
99066
94945
98621
...

result:

ok 100000 numbers

Test #18:

score: 5
Accepted
time: 300ms
memory: 64492kb

input:

100000 100000
34120 34039 56199
92961 92165 16304
96474 96156 51162
44343 44155 24750
55177 54729 88470
54013 54039 81914
61486 61281 16236
65391 65324 58788
9975 10232 5223
73153 72682 13303
67307 67334 88990
87736 87013 33817
34048 33825 1519
13297 13760 97226
7215 7618 70214
35955 36240 39046
114...

output:

98764
91634
99053
99723
99768
99113
98790
99384
98477
98941
9571
98801
37354
98749
98632
98635
99562
99987
98726
98675
83343
99668
85578
98346
98593
98444
14104
99598
98989
60614
99453
73426
32638
49066
98836
98401
26777
99667
44668
34454
99557
99414
98214
98184
98640
98318
88691
98970
285
98771
196...

result:

ok 100000 numbers

Test #19:

score: 5
Accepted
time: 273ms
memory: 65456kb

input:

100000 100000
13042 13684 31388
12618 12982 44532
3790 4458 11977
74445 74070 23330
75921 75641 6287
56703 56758 11960
1589 2485 28300
18775 18773 66489
26133 26822 97578
22751 22994 59497
24624 24635 17466
29383 29166 13399
87897 87033 20723
61522 61473 30820
59230 59007 13824
14935 14758 2671
7331...

output:

98411
99745
99228
98262
99771
8385
99304
71417
-1
99330
99052
99342
6678
99862
99437
98200
98910
99211
99247
98879
98209
99262
99799
98658
99561
99652
244
99468
74414
99606
99505
86766
84494
98787
83384
98391
99680
98064
99676
98435
99583
99734
99585
99949
99695
98748
99492
98316
99574
99610
98689
9...

result:

ok 100000 numbers

Test #20:

score: 5
Accepted
time: 309ms
memory: 66420kb

input:

100000 100000
91968 91328 6577
32279 32700 72759
11109 11860 72795
4544 4986 21909
96665 96455 24108
59393 59379 42011
41696 41689 40365
72163 72222 74189
42291 42312 89929
72353 72305 5688
81945 81937 45946
71034 70419 92986
41741 41340 39926
9744 10086 64417
11242 11396 57437
93919 93276 66299
351...

output:

98297
98711
86088
57994
99148
99795
74255
99842
99579
89911
98781
99423
99882
27752
98437
99650
3740
98511
99248
99714
98277
19627
25907
99842
98203
98843
98927
96335
99628
59865
94501
99343
99308
99761
98637
99497
80019
99594
99020
11971
10357
99691
98572
98246
98958
99272
99792
12448
98472
7839
77...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed