QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#84735#5657. Hungry CowPdw20079.090909 396ms50816kbC++144.7kb2023-03-06 18:05:402023-03-06 18:05:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-06 18:05:41]
  • 评测
  • 测评结果:9.090909
  • 用时:396ms
  • 内存:50816kb
  • [2023-03-06 18:05:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls k<<1
#define rs k<<1|1
#define lson ls,l,mid
#define rson rs,mid+1,r
const int N=1e5+5,mod=1e9+7,inv2=5e8+4;
const ll inf=1e17;
int n,ans;
vector<pair<ll,int> > v[N<<2];
map<ll,pair<int,int> > mp;
map<ll,pair<int,int> >::iterator koishi;
void updt(int k,int l,int r,int pl,int pr,ll pos,int val) {
    if(!val) return;
    if(pl<=l&&r<=pr) {
        v[k].push_back(make_pair(pos,val));
        return;
    }
    int mid=(l+r)>>1;
    if(mid>=pl) updt(lson,pl,pr,pos,val);
    if(mid<pr) updt(rson,pl,pr,pos,val);
    return;
}
int top;
vector<pair<ll,ll> > stadd[N],stdel[N];
int lstans[N];
multiset<pair<ll,ll> > st;
set<pair<ll,ll> >::iterator it;

void Print() {
    cerr<<"ans = "<<ans<<endl;
    for(it=st.begin();it!=st.end();it++) cerr<<(*it).first<<" "<<(*it).second<<endl;
    return;
}
void add(ll pos,int val) {
    // cerr<<"=============================================\n";
    // cerr<<pos<<" "<<val<<endl;
    // Print();
    top++;
    stadd[top].clear();
    stdel[top].clear();
    while(true) {
        if(!val) break;
        it=st.lower_bound(make_pair(pos,0));
        if(it==st.end()) {
            st.insert(make_pair(pos+val-1,pos));
            stadd[top].push_back(make_pair(pos+val-1,pos));

            ans+=(pos+pos+val-1)*val%mod*inv2%mod;
            if(ans>=mod) ans-=mod;
            break;
        }
        ll r=(*it).first,l=(*it).second;
        if(l>pos) {
            ll t=min(l-pos,val*1ll);
            if(t==l-pos) {
                val-=t;
                st.erase(make_pair(r,l));
                stdel[top].push_back(make_pair(r,l));
                ans-=(l+r)*(r-l+1)%mod*inv2%mod;
                if(ans<0) ans+=mod;

                st.insert(make_pair(r,pos));
                stadd[top].push_back(make_pair(r,pos));

                ans+=(pos+r)*(r-pos+1)%mod*inv2%mod;
                if(ans>=mod) ans-=mod;
                pos=r;
                continue;
            }
            st.insert(make_pair(pos+val-1,pos));
            stadd[top].push_back(make_pair(pos+val-1,pos));

            ans+=(pos+pos+val-1)*val%mod*inv2%mod;
            if(ans>=mod) ans-=mod;
            break;
        }
        it++;
        ll l2=inf,r2=inf;
        if(it!=st.end()) l2=(*it).second,r2=(*it).first;

        st.erase(make_pair(r,l));
        stdel[top].push_back(make_pair(r,l));

        ans-=(l+r)*(r-l+1)%mod*inv2%mod;
        if(ans<0) ans+=mod;

        ll t=min(l2-r-1,val*1ll);
        if(t==l2-r-1) {
            val-=t;
            st.erase(make_pair(r2,l2));
            stdel[top].push_back(make_pair(r2,l2));
            ans-=(l2+r2)*(r2-l2+1)%mod*inv2%mod;
            if(ans<0) ans+=mod;

            st.insert(make_pair(r2,l));
            stadd[top].push_back(make_pair(r2,l));

            ans+=(l+r2)*(r2-l+1)%mod*inv2%mod;
            if(ans>=mod) ans-=mod;
            pos=r2;
            continue;
        }
        st.insert(make_pair(r+val,l));
        stadd[top].push_back(make_pair(r+val,l));

        ans+=(l+r+val)*(r+val-l+1)%mod*inv2%mod;
        if(ans>=mod) ans-=mod;
        break;
    }
    lstans[top]=ans;
    // Print();
    return;
}
// map<pair<ll,ll> ,int> qwq;
void del(int koishi) {
    // cerr<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
    while(top>koishi) {
        // Print();
        // qwq.clear();
        for(int i=0;i<stdel[top].size();i++) {
            st.insert(make_pair(stdel[top][i].first,stdel[top][i].second));
            // cerr<<"add : "<<stdel[top][i].first<<" "<<stdel[top][i].second<<endl;
        }
        for(int i=0;i<stadd[top].size();i++) {
            it=st.lower_bound(make_pair(stadd[top][i].first,stadd[top][i].second));
            st.erase(it);
            // cerr<<"del : "<<stadd[top][i].first<<" "<<stadd[top][i].second<<endl;
        }
        top--;
        ans=lstans[top];
    }
    return;
}
void qury(int k,int l,int r) {
    int _=top;
    for(int i=0;i<v[k].size();i++) add(v[k][i].first,v[k][i].second);
    if(l==r) {
        //Print();
        printf("%d\n",ans);
        del(_);
        return;
    }
    int mid=(l+r)>>1;
    qury(lson);
    qury(rson);
    del(_);
    return;
}
int main() {
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        ll x;
        int y;
        scanf("%lld%d",&x,&y);
        if(mp.count(x)!=0) updt(1,1,n,mp[x].first,i-1,x,mp[x].second);
        mp[x]=make_pair(i,y);
    }
    for(koishi=mp.begin();koishi!=mp.end();koishi++) {
        int x=(*koishi).second.first,y=(*koishi).second.second;
        updt(1,1,n,x,n,(*koishi).first,y);
    }
    qury(1,1,n);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 4.54545
Accepted
time: 2ms
memory: 17848kb

input:

3
4 3
1 5
1 2

output:

15
36
18

result:

ok 3 number(s): "15 36 18"

Test #2:

score: 4.54545
Accepted
time: 2ms
memory: 17588kb

input:

9
1 89
30 7
101 26
1 24
5 1
60 4
5 10
101 0
1 200

output:

4005
4656
7607
3482
3507
3753
4058
1107
24531

result:

ok 9 numbers

Test #3:

score: 0
Wrong Answer
time: 233ms
memory: 38144kb

input:

5000
1 255364995
414918035 212844
1 112266691
321122438 191414
1 277615842
848755093 61676
1 432591689
892259443 53755
1 263753018
173404455 173565
1 178341924
878941367 221276
1 65332960
439468128 240741
1 812238377
191076090 108732
1 180383041
927440330 112995
1 595696140
579818784 85614
1 5057816...

output:

235118030
699918971
430865692
80346613
848027326
568710394
340195238
190991083
826211664
180951671
569935857
679922008
650993948
624850177
428416731
646484944
727440627
230673871
429374754
412788182
52678570
76241310
668853821
636690710
209140532
869111458
915919167
837020724
313374684
328391122
903...

result:

wrong answer 2501st numbers differ - expected: '948499983', found: '345115135'

Test #4:

score: 0
Wrong Answer
time: 300ms
memory: 50816kb

input:

100000
1 500000000
1000000001 500000000
2000000001 500000000
3000000001 500000000
4000000001 500000000
5000000001 500000000
6000000001 500000000
7000000001 500000000
8000000001 500000000
9000000001 500000000
10000000001 500000000
11000000001 500000000
12000000001 500000000
13000000001 500000000
1400...

output:

375000007
250000035
625000091
500000168
875000273
750000399
125000546
721
375000924
-41170856
-957342615
-1373514346
1005281233
589109551
-327062110
-743233743
-1659405355
-2075576939
303218787
887047259
970875752
554704266
638532808
222361371
306189962
890018581
973847221
557675882
350332567
-35701...

result:

wrong answer 10th numbers differ - expected: '250001148', found: '-41170856'

Test #5:

score: 0
Wrong Answer
time: 366ms
memory: 49924kb

input:

100000
49998999950002 500000000
49997999950003 500000000
49996999950004 500000000
49995999950005 500000000
49994999950006 500000000
49993999950007 500000000
49992999950008 500000000
49991999950009 500000000
49990999950010 500000000
49989999950011 500000000
49988999950012 500000000
49987999950013 500...

output:

300274662
600549296
900823902
201098473
501373023
801647545
101922032
402196498
702470936
2745339
-696980286
-1396705939
-2096431620
498809960
-200915777
-900641542
-1600367335
994874133
-1708646994
-2117200867
-1525754761
-934308683
-342862633
248583389
840029383
726442610
317888541
909334451
50078...

result:

wrong answer 1st numbers differ - expected: '376399979', found: '300274662'

Test #6:

score: 0
Wrong Answer
time: 396ms
memory: 48288kb

input:

100000
92303348842417 121458
92270522994821 852054850
93765096269940 752161890
97779083359973 984327853
90030769679569 439157849
99462493683485 45660
95578441605501 614317411
92236129196525 474149928
96065411631989 429943696
90394247621798 382840249
89263934750729 791122796
93577089467158 99679481
9...

output:

310213631
32687408
-231765365
128470288
57794074
897912134
-47196752
348021746
200486236
57892004
300661832
173827810
769656961
464940005
-322531787
-1131288485
-1371169343
-1214148653
-1795917499
-258822980
-231078579
-1070842391
-1908702506
-1933049523
-1210218839
-813381380
-337486325
-474044305
...

result:

wrong answer 1st numbers differ - expected: '601385635', found: '310213631'

Test #7:

score: 0
Wrong Answer
time: 378ms
memory: 47944kb

input:

100000
98001410246890 641673458
94816407430628 495030536
95979591652947 43208
95979591652947 183686
97163521776290 904784415
91640049592559 875129980
95914835187460 844802426
94846379383324 974270031
99639652388956 311664277
99298294827771 913614463
99476866913169 221766107
97248342663994 669489020
...

output:

594698891
546408659
590783487
-213281414
153560025
728733041
128676452
663433701
24956262
-643736874
-888550799
-1572782449
-1190604241
-1096693762
-1279669143
-1845393000
491904563
615584393
68619119
-1765570907
-1145575098
-1155045224
-1429102527
-1744085932
-1668101588
128232128
-501354920
228508...

result:

wrong answer 1st numbers differ - expected: '805408268', found: '594698891'

Test #8:

score: 0
Wrong Answer
time: 365ms
memory: 47524kb

input:

100000
97338601145206 191999210
97657969728741 875988993
92559675348135 8552565
99354409480201 960853995
93648768326445 343671323
97400841247229 104463842
98844341051398 508718383
96144328794112 187050711
98030257583732 365513
92378049740181 852725611
98301676983212 360931360
99458914124366 80234576...

output:

287359861
641887613
244379267
196161969
915968994
356582321
-492769823
116323819
-865369345
-1573150932
-1732213391
-1485534874
-879004623
-963934656
-137215375
837468853
-28609868
-827425921
-1268885
1125938510
-1768415393
-1263009553
-1869303783
847439149
-1651071753
-7161945
-746681775
63575832
-...

result:

wrong answer 1st numbers differ - expected: '201835835', found: '287359861'

Test #9:

score: 0
Wrong Answer
time: 337ms
memory: 47056kb

input:

100000
96119987448606 658315028
98644701118435 280992389
98180676447908 56168
99822794299596 237183170
94655838918825 563695131
95744558879343 686204820
93739311062176 263266841
97630990881452 96901680
98683433984282 380708175
98141920320037 147598812
98095513966598 814629225
97882900659205 55097258...

output:

-446816507
-345220265
-935187083
-1520950947
1017279046
827263308
327038546
-572492299
-107418520
-330996882
437753243
600724477
778989539
43542726
515461197
373968095
920421297
119831153
980063292
934843248
158262945
-534661820
-83574346
-285389804
-1185508292
545017330
35517693
389647291
189576977...

result:

wrong answer 1st numbers differ - expected: '284288958', found: '-446816507'

Test #10:

score: 0
Wrong Answer
time: 349ms
memory: 46764kb

input:

100000
98169641631056 170946511
99452522210742 393032132
98797460964704 393706377
98747209012224 529219651
99152468691953 362194103
99410753036475 215295
97096873124809 1315725
96106202009957 124516158
95176405230280 853965254
99359463136784 622839995
96635771520630 550456203
96368792029394 93630831...

output:

51119531
-255151632
-15889629
-40898897
-955224228
-192287875
-833377976
-499715256
-175932453
-1022194177
-626758252
-763173584
-1235997931
-1937182740
602230599
33379678
23124303
-143136000
495690689
-990220870
-127084523
621123065
-357488172
-324725748
-674620916
499899415
-253249325
518446939
98...

result:

wrong answer 1st numbers differ - expected: '692991104', found: '51119531'

Test #11:

score: 0
Time Limit Exceeded

input:

100000
97499080763005 475255826
97499083333242 9347
97499080763005 395470349
97499924236501 4654
97499080763005 148122052
97499213182916 2365
97499080763005 544025506
97499777050346 9912
97499080763005 41736833
97499401163067 12607
97499080763005 127843558
97499125181305 7144
97499080763005 13152858...

output:

-192181171
-419787691
-841575670
-610424993
-18062464
-294101299
-662851015
-255627028
988180388
926203384
36891771
-461272787
-530559260
-313876463
-30680699
222362408
375581813
667329514
323151850
105259202
372261531
569951357
91211397
484463098
607241947
479510600
-137984315
324906620
531925338
3...

result:


Test #12:

score: 0
Time Limit Exceeded

input:

100000
98999026537234 929244389
98999182418499 5182
98999026537234 774643967
98999646433835 17857
98999026537234 760743518
98999980664456 7597
98999026537234 573421161
98999090975969 6621
98999026537234 95191521
98999947586610 17798
98999026537234 953104244
98999116462517 15643
98999026537234 100617...

output:

376693394
659363382
-402533961
-832741500
-885596105
-13590396
347999551
-859576058
-89043094
881809811
871296437
427069484
520818219
470048233
785945174
742822452
172127236
189822642
339399779
365461925
798176571
118829702
796857096
366622291
788396357
772054930
-47649900
586633701
457307248
687856...

result:


Test #13:

score: 0
Time Limit Exceeded

input:

100000
99499024212061 630391525
99499061152079 3864
99499024212061 16505706
99499878275777 4812
99499024212061 776185964
99499757280269 12059
99499024212061 356565635
99499399237611 8902
99499024212061 972528120
99499256994518 9171
99499024212061 419476867
99499909552451 17146
99499024212061 6767939...

output:

389219660
-197499365
984416494
907476807
541955007
261961574
927803723
-219570333
-514458741
-484010076
121511919
512642791
21816
-36344001
460852581
33047488
-32017164
-45373939
369886841
24859507
353062649
304706646
738194683
818665223
417913208
175882412
-187009513
-128246553
688890859
717412706
...

result:


Test #14:

score: 0
Time Limit Exceeded

input:

99999
10490328589436 1000000000
13762508396295 1000000000
40632115714511 1000000000
32834989282081 1000000000
29091918306598 1000000000
24352818172350 1000000000
23447797352860 1000000000
38073075086135 1000000000
14288530509239 1000000000
36463049009868 1000000000
10562334120356 1000000000
34490016...

output:

637821776
651095175
230415955
734723350
951508510
531410194
791860159
310098721
571803177
227597061
497329907
690258306
687233692
682888912
958757981
41193455
-426211850
166979191
807171835
103555656
-533519666
-1280700140
1035446844
691782276
971884012
896031665
368778040
312279632
680035176
944343...

result:


Test #15:

score: 0
Time Limit Exceeded

input:

99999
61585049539216 1000000000
58981995705940 1000000000
44247484521936 1000000000
70916218483207 1000000000
47696673638497 1000000000
60781033156530 1000000000
55859922511212 1000000000
59143999312357 1000000000
57175954090596 1000000000
71328224891428 1000000000
46047599292678 1000000000
47510666...

output:

500786088
488782108
347203299
-227314
636218232
583607892
791122693
-196042308
152885011
949048961
934450780
444943837
201528406
-20823041
703196772
795932632
972115013
907795720
372922580
838619800
586356874
913478921
19876529
-65971923
558054527
-436319599
379495338
-535164197
-749158912
-13492324...

result:


Test #16:

score: 0
Time Limit Exceeded

input:

99999
21219982576425 1000000000
42260400232639 1000000000
26412110792985 1000000000
11035481121988 1000000000
13219690258669 1000000000
19550933913223 1000000000
32679237390903 1000000000
15679803374289 1000000000
23896051833122 1000000000
20099950455987 1000000000
14778766729432 1000000000
21547991...

output:

-863771688
-1813442369
790654623
-109544881
809813424
-11265278
706196766
1090941749
302623741
186624482
362695504
245208806
71853776
-642593534
-455973837
-1439007844
200442304
-699973524
-124899676
-1531485740
-1647305189
-866120602
858383402
190982897
-720177532
-463132655
-1426181765
-438933639
...

result:


Test #17:

score: 0
Time Limit Exceeded

input:

99999
28503598869279 1000000000
32397709666940 1000000000
25833502058723 1000000000
38020841213328 1000000000
54560138759501 1000000000
42230929758874 1000000000
28972613620824 1000000000
28498598787317 1000000000
54070131397843 1000000000
22084267818956 1000000000
37776835952805 1000000000
44465973...

output:

87825690
-765498272
-851420959
50956714
799922083
17082320
151898077
-759702751
-527113686
-466536917
-956875498
-506900360
-1422415421
106495108
-347105864
-197800259
-984524626
-1310115206
-1557676537
-1222942012
-287265575
-71886565
-230426342
238259290
151328876
114501828
-3773500
222947035
-173...

result:


Test #18:

score: 0
Time Limit Exceeded

input:

99999
18175781548542 1000000000
40883228277118 1000000000
33828113807745 1000000000
17817771477758 1000000000
22749897023579 1000000000
18015777423352 1000000000
28920025506062 1000000000
18799798298070 1000000000
27979006765970 1000000000
17103749421004 1000000000
24329932307643 1000000000
29798042...

output:

-369965022
-731386241
-1545286052
805902233
206523109
106522614
-186000865
818293872
356449126
278448572
-358253914
-427794418
293302611
754822547
137744151
-63413
-182306398
-244842072
587392670
246028071
461480065
-18726275
771575625
468666576
-85797032
518716879
63211549
911214490
767991388
92130...

result:


Test #19:

score: 0
Time Limit Exceeded

input:

99999
13631696063382 1000000000
19095823575649 1000000000
18048800926387 1000000000
17060779354093 1000000000
15768748767399 1000000000
30886037572930 1000000000
26814970558482 1000000000
8165534157289 1000000000
27914989206121 1000000000
34170089895536 1000000000
27764986366439 1000000000
145187181...

output:

776005413
285867529
856659404
733813129
589090677
192559038
-37046079
537031305
236306380
-183555281
-514485749
154627705
181523038
-916611319
-598416848
-311497644
-392870500
-1284366561
-947617319
-1027135253
-1633469877
1067759245
360113356
295703482
238430186
-319114859
496749953
-167919305
2509...

result:


Test #20:

score: 0
Time Limit Exceeded

input:

99999
71091006018203 1000000000
42267334298998 1000000000
53421686894439 1000000000
52992676205010 1000000000
49055576058012 1000000000
70721000416119 1000000000
43151374327143 1000000000
70716000332404 1000000000
51528640431406 1000000000
65945925001029 1000000000
39524135856472 1000000000
66414932...

output:

-392435058
-1171741913
-445620653
-1250782332
270304177
-436054347
-448027082
137372165
-121097708
-472687562
-93774559
-348260261
375782375
-412635640
-449228836
51308113
-790439078
-198963191
164299660
438979584
274512126
278677240
237073349
-25837053
968191451
-448645793
434054960
321376177
53327...

result:


Test #21:

score: 0
Time Limit Exceeded

input:

99999
43981987091230 1000000000
41793950053258 1000000000
23385527966154 1000000000
32049759202175 1000000000
48927065970165 1000000000
26694629471843 1000000000
27661655640242 1000000000
37241867113918 1000000000
49110069037684 1000000000
20323405372655 1000000000
43304975621086 1000000000
48021052...

output:

-506760824
-455426587
-562240722
-697792299
-824656408
118575085
305614958
-514901516
-1486669336
-2066374374
-1946149214
851635914
10610396
1005940385
764115065
92352887
-840661714
-809644043
-834559916
-219453175
-835818969
-375187824
-284088682
488543581
-23052461
-1594890393
1077097999
225061060...

result:


Test #22:

score: 0
Time Limit Exceeded

input:

99999
31159466866911 1000000000
28413414847308 1000000000
25948364344910 1000000000
31236468095715 1000000000
22036273821032 1000000000
24056321657736 1000000000
36031551606814 1000000000
37935581367999 1000000000
40624624246259 1000000000
18857191994835 1000000000
22179277697755 1000000000
29154428...

output:

154435839
150958924
534974536
60264498
-465315611
-92322089
-560815881
-218977069
-1199378896
-1989162728
1094342369
698260640
726546665
-2093322223
-1156926010
-1910671741
-1146377358
-634468117
297419859
116559185
355723742
-501408249
-916541814
-560178703
-772015229
-49391074
-573483026
-11780433...

result: