QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397511#5308. RPG Pro League2745518585AC ✓152ms11844kbC++202.7kb2024-04-24 11:12:522024-04-24 11:12:53

Judging History

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

  • [2024-04-24 11:12:53]
  • 评测
  • 测评结果:AC
  • 用时:152ms
  • 内存:11844kb
  • [2024-04-24 11:12:52]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
const int N=2000001;
int n,m,b[N],f[16],p[16],g[8];
bool h[N];
ll s;
struct str
{
    int a,b,t;
    friend bool operator<(str a,str b)
    {
        if(a.b!=b.b) return a.b<b.b;
        return a.t<b.t;
    }
}a[N];
set<str> Set[8][2];
void add(int x)
{
    if(h[x])
    {
        for(auto j=1;j<=15;++j) if(j&g[a[x].a]) --f[j];
        s-=a[x].b;
    }
    h[x]^=1;
    if(h[x])
    {
        for(auto j=1;j<=15;++j) if(j&g[a[x].a]) ++f[j];
        s+=a[x].b;
    }
}
int sum()
{
    int s=1e9;
    for(int i=1;i<=15;++i)
    {
        s=min(s,f[i]/p[i]);
    }
    return s;
}
bool cmp(int x,int y)
{
    return a[x].b>a[y].b;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)
    {
        static char z[5];
        z[0]=z[1]=z[2]=0;
        scanf("%s%d",z,&a[i].b);
        if(z[0]=='D'||z[1]=='D'||z[2]=='D') a[i].a|=1;
        if(z[0]=='S'||z[1]=='S'||z[2]=='S') a[i].a|=2;
        if(z[0]=='B'||z[1]=='B'||z[2]=='B') a[i].a|=4;
        a[i].t=i;
    }
    for(int i=1;i<=n;++i) b[i]=i;
    sort(b+1,b+n+1,cmp);
    for(int i=1;i<=7;++i)
    {
        if(i&1) g[i]|=1;
        if(i&2) g[i]|=2;
        if(i&3) g[i]|=4;
        if(i&4) g[i]|=8;
    }
    for(int i=1;i<=15;++i) p[i]=p[i^(i&-i)]+1;
    for(int i=1;i<=n;++i) add(i);
    int q=sum();
    for(int i=1;i<=n;++i)
    {
        add(b[i]);
        if(sum()<q) add(b[i]);
    }
    // printf("%d %lld\n",q,s);
    for(int i=1;i<=n;++i)
    {
        Set[a[i].a][h[i]].insert(a[i]);
    }
    scanf("%d",&m);
    for(int i=1;i<=m;++i)
    {
        int x,k;
        scanf("%d%d",&x,&k);
        Set[a[x].a][h[x]].erase(a[x]);
        if(h[x]) s-=a[x].b;
        a[x].b=k;
        Set[a[x].a][h[x]].insert(a[x]);
        if(h[x]) s+=a[x].b;
        int u=0;
        ll v=s;
        for(int i=1;i<=7;++i)
        {
            int t=0;
            if(h[x])
            {
                if(!Set[i][0].empty()) t=Set[i][0].begin()->t;
            }
            else
            {
                if(!Set[i][1].empty()) t=prev(Set[i][1].end())->t;
            }
            if(t!=0)
            {
                add(x),add(t);
                if(sum()==q&&s<v) v=s,u=t;
                add(x),add(t);
            }
        }
        if(u!=0)
        {
            Set[a[x].a][h[x]].erase(a[x]);
            Set[a[u].a][h[u]].erase(a[u]);
            add(x),add(u);
            Set[a[x].a][h[x]].insert(a[x]);
            Set[a[u].a][h[u]].insert(a[u]);
        }
        printf("%lld\n",s);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3788kb

input:

5
BS 3
D 3
B 2
D 4
D 5
2
5 2
1 5

output:

10
12

result:

ok 2 number(s): "10 12"

Test #2:

score: 0
Accepted
time: 148ms
memory: 11844kb

input:

100000
B 727564174
S 231637747
D 246625257
S 975124756
D 844292741
S 809641006
B 396062588
B 883224128
B 311130283
S 434433581
S 509817048
S 993501344
S 508399542
B 279564062
D 950946642
D 819528264
D 412285620
B 968540732
S 953428318
D 902181790
S 172330493
D 725075
B 135580649
D 714478555
B 466916...

output:

40721766963064
40720937650054
40721120372880
40720722768213
40721029809776
40720546822562
40719680807733
40720084910620
40720153432078
40720873952927
40721146683113
40721696875436
40722235723316
40722133896063
40723047443192
40723419347010
40722633976087
40722282806304
40722071958869
40721278798949
...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 144ms
memory: 11744kb

input:

100000
S 139759881
S 606246897
D 295439937
S 30506154
B 815842927
D 195502949
S 172358189
B 763560428
S 862087943
B 413481091
B 775973599
B 336841814
S 116523655
D 670479401
S 405979654
D 246440323
B 764165518
S 20267667
S 327264314
B 44539411
B 353491632
D 5202858
S 842200033
S 337952200
D 6150168
...

output:

40524529913817
40524860528295
40524824503871
40524293726866
40524353142964
40524176391157
40524132308308
40524134826811
40524107274580
40524341365401
40524194084164
40524572093940
40524910630137
40525296284478
40525633925207
40525793456210
40526041232042
40526041232042
40526144290799
40526737278038
...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 151ms
memory: 11820kb

input:

100000
B 567185557
S 731841946
S 365565517
D 767568967
B 450159068
D 658059427
S 790559143
B 356623472
S 541664149
D 447906802
B 407933323
S 403512209
D 187294244
D 351683584
S 504286757
D 212023807
B 51119045
S 84059041
S 819097063
D 115224344
B 104478594
B 446088838
D 153595287
S 749172175
S 57160...

output:

40639770818547
40639473223932
40639909468709
40639327970968
40639021798510
40639377404325
40638848317225
40638755074708
40638463360482
40638463360482
40638225443217
40638907566106
40638907566106
40638707391259
40638642781389
40638809562003
40637986313647
40637481713492
40636989271046
40636464147095
...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 121ms
memory: 11840kb

input:

100000
BS 609181774
BS 498815665
BS 729225393
S 366911976
D 192782776
DB 109052372
D 927091614
SD 120687185
D 619604491
DB 405398892
BS 947957264
DB 134896320
S 909342292
DS 374808683
SD 810910022
D 636083341
D 719767505
D 576713707
DB 327091245
SD 128393617
B 464665485
DB 186653465
S 50744850
BS 31...

output:

49922035989330
49921636770968
49921944461352
49922449756073
49922666981649
49922155391929
49922220626762
49922165472452
49922033364853
49922182879778
49922118499498
49921629498341
49921194947559
49921237943096
49920830551816
49920785993225
49921523763744
49920936362665
49920399195989
49920353383077
...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 149ms
memory: 11768kb

input:

100000
S 46980313
DS 746577279
S 119614887
D 32418943
B 952739459
S 532231646
SD 559263381
DS 631559122
SB 335561329
SD 935559531
DB 548708848
BD 8298741
DS 403723074
DS 559038896
SB 43327419
SD 430897629
B 483781810
B 31916773
B 39977980
S 405078517
D 323989135
SD 584417860
SB 776661769
D 467791168...

output:

42348275359402
42348652439619
42348713198459
42348631107452
42349074844557
42349760441910
42349962186466
42350429498431
42350447771721
42350361082730
42349972717124
42350266522340
42350463555914
42351167696055
42350739802238
42350725554192
42351107085086
42350772822134
42349881535618
42350109052615
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 150ms
memory: 11828kb

input:

100000
BS 213295369
B 455710761
SB 373454236
DB 673322458
S 651168441
BS 359903245
BD 751934633
SD 632609134
S 358152611
S 160649972
D 146822438
B 754830402
B 385092410
B 851559764
DS 481485147
B 224375164
D 961859623
DB 985459185
B 582943091
B 316407251
DS 305843239
DS 723438991
S 53429344
B 523111...

output:

45600208273121
45600317533935
45600175773836
45600173792927
45599452402298
45599812001804
45599878168987
45600637494399
45600782960729
45601107349004
45601024544203
45600077092341
45600360724694
45600356341282
45600663553626
45600478170427
45601258145258
45601572720352
45601860925268
45602282587440
...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 152ms
memory: 11840kb

input:

100000
S 716049090
D 833450560
SD 670462747
SB 446815258
B 384907056
D 984726104
SB 462243694
D 922590298
BD 759638240
DS 19626890
SB 248370274
SD 668142001
D 335754916
B 726719900
BD 453285618
D 322601083
D 748915428
DB 977946001
BD 918781134
SB 548154938
S 732129575
B 165403934
DB 307460261
B 5705...

output:

49045162855443
49045050545344
49045590587244
49046369263442
49046304995206
49045800881106
49045291887266
49045217335835
49044870222977
49044225198944
49044835834249
49045020093554
49045243504559
49045344873512
49045291814515
49044883632804
49044186683347
49043700349817
49044284292286
49044627186893
...

result:

ok 100000 numbers

Test #9:

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

input:

100000
D 960395655
B 122062291
SB 943474832
S 570975390
B 123731786
S 774351291
SD 856577683
DS 198978387
BS 934036917
BS 91010215
DS 387466221
BD 12179611
BS 860542232
BD 330196269
SB 26230686
S 732137135
D 536823278
DS 596330655
D 526094623
S 676662638
BD 894521450
SD 208119759
S 825586140
DS 7300...

output:

50012421513787
50012188224437
50012089226755
50012449040900
50012737290301
50012412928158
50012451727620
50013117114082
50013616855009
50013660180722
50013565703915
50013578958010
50013544230467
50013431019751
50013791549050
50013557409907
50013800945077
50013305887273
50013458257335
50013127389538
...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 143ms
memory: 11832kb

input:

100000
BD 167885928
B 410609125
B 867926765
D 25698987
B 964971589
DSB 761993255
D 716924891
SDB 449179974
D 655788083
DSB 251063578
BSD 636094691
SBD 269449771
D 416812799
S 196094133
BDS 899848895
BSD 201208478
SDB 654682908
S 210099670
S 459258687
SD 787381819
SDB 75643134
B 794516075
B 341054234...

output:

44681215929094
44681140738264
44680930941960
44681518144147
44682382390432
44682221858538
44682184620437
44682238048343
44681980767149
44682265890653
44682001502128
44682027275138
44682237188441
44682302542078
44682286644950
44681643705300
44681615590582
44681497821291
44681221388134
44682128554988
...

result:

ok 100000 numbers

Test #11:

score: 0
Accepted
time: 141ms
memory: 11836kb

input:

100000
BDS 896623632
S 727737495
S 575894623
DB 87537832
S 392667603
S 454633578
B 848685103
BS 871609322
B 934539797
D 721419925
BDS 402351750
S 154060393
DB 8064179
S 323796100
DBS 478313825
B 576680349
DSB 326542444
S 847087723
BD 316375670
D 676173497
D 206424750
BDS 891334275
DB 32418913
SD 574...

output:

46778674719333
46778848243922
46778957655091
46778937757904
46778899686335
46778941204115
46779048062288
46779205742495
46779469558777
46779396882706
46778679387011
46778246708121
46777492984199
46777042157595
46777151909181
46777537135258
46777670986261
46777789945939
46778245232217
46777814046064
...

result:

ok 100000 numbers

Test #12:

score: 0
Accepted
time: 141ms
memory: 11804kb

input:

100000
B 209787110
S 743547852
BDS 632112547
DSB 835672184
SBD 542035029
SDB 679878940
D 799107065
DB 96949934
B 381373295
S 894375953
SB 523946265
DBS 25024985
D 24381368
D 542488317
DB 888440956
SD 737136220
SD 646535540
DS 692254809
DSB 688491183
DS 202691109
DSB 615672839
B 975992261
DB 76178577...

output:

42579864423434
42580017947180
42580061595055
42581027647286
42581235297075
42581252060401
42580753810484
42580508092543
42581187959009
42581255726469
42581819067734
42581643117279
42581732924457
42582183780563
42582064698786
42582707711867
42582376025312
42582433674019
42582377573748
42582076215383
...

result:

ok 100000 numbers

Test #13:

score: 0
Accepted
time: 82ms
memory: 11844kb

input:

100000
DB 1
D 2
DSB 3
S 4
DSB 5
D 6
S 7
D 8
D 9
DS 10
SBD 11
BS 12
DSB 13
S 14
D 15
SBD 16
BDS 17
DS 18
SDB 19
BS 20
S 21
S 22
B 23
SBD 24
BD 25
BDS 26
D 27
DSB 28
BS 29
BS 30
B 31
B 32
S 33
B 34
D 35
DB 36
SB 37
BD 38
D 39
DB 40
S 41
DB 42
SB 43
BDS 44
B 45
SBD 46
DBS 47
B 48
DSB 49
DBS 50
DSB 51
D...

output:

4474057839
4474157836
4474257831
4474357824
4474457815
4474557804
4474657791
4474757776
4474857759
4474957740
4475057719
4475157696
4475257671
4475357644
4475457615
4475557584
4475657551
4475757516
4475857479
4475957440
4476057399
4476157356
4476239587
4476339540
4476439491
4476539440
4476639387
447...

result:

ok 100000 numbers

Test #14:

score: 0
Accepted
time: 86ms
memory: 11756kb

input:

100000
D 1
D 2
SD 3
S 4
SD 5
SB 6
SB 7
DS 8
SD 9
B 10
B 11
SB 12
BS 13
S 14
DS 15
S 16
B 17
SD 18
DB 19
BS 20
SB 21
D 22
DB 23
DS 24
SD 25
D 26
DS 27
DB 28
S 29
S 30
S 31
B 32
DB 33
B 34
D 35
SB 36
D 37
SD 38
B 39
DB 40
B 41
DB 42
SB 43
DS 44
BD 45
SD 46
BD 47
SD 48
SB 49
DS 50
D 51
BD 52
S 53
BS 54...

output:

4412083907
4412183904
4412283899
4412383892
4412483883
4412583872
4412683859
4412783844
4412883827
4412964351
4413044877
4413144854
4413244829
4413344802
4413444773
4413544742
4413625264
4413725229
4413825192
4413925153
4414025112
4414125069
4414225024
4414324977
4414424928
4414524877
4414624824
441...

result:

ok 100000 numbers

Test #15:

score: 0
Accepted
time: 84ms
memory: 11752kb

input:

100000
S 1
S 2
D 3
D 4
S 5
D 6
D 7
B 8
B 9
D 10
B 11
S 12
S 13
B 14
B 15
B 16
B 17
S 18
D 19
S 20
S 21
S 22
B 23
S 24
S 25
S 26
D 27
S 28
B 29
B 30
D 31
S 32
D 33
B 34
S 35
B 36
S 37
S 38
S 39
S 40
S 41
B 42
S 43
B 44
S 45
B 46
D 47
D 48
B 49
D 50
S 51
S 52
S 53
B 54
S 55
B 56
S 57
B 58
D 59
S 60
D ...

output:

4077033794
4077133791
4077233786
4077333779
4077433770
4077533759
4077633746
4077700606
4077767466
4077867447
4077934313
4078034290
4078134265
4078201129
4078267994
4078334861
4078401728
4078501693
4078601656
4078701617
4078801576
4078901533
4078968396
4079068349
4079168300
4079268249
4079368196
407...

result:

ok 100000 numbers

Test #16:

score: 0
Accepted
time: 95ms
memory: 11696kb

input:

100000
SB 100000
DBS 99999
D 99998
BS 99997
D 99996
S 99995
S 99994
BD 99993
BDS 99992
B 99991
BD 99990
SBD 99989
SD 99988
BSD 99987
SBD 99986
SB 99985
S 99984
D 99983
S 99982
SB 99981
BD 99980
DB 99979
SBD 99978
B 99977
D 99976
DS 99975
S 99974
B 99973
DBS 99972
BSD 99971
S 99970
B 99969
SD 99968
B...

output:

4512602763
4512502766
4512402771
4512302778
4512202787
4512102798
4512002811
4511902826
4511802843
4511732297
4511632318
4511532341
4511432366
4511332393
4511232422
4511132453
4511032486
4510932521
4510832558
4510732597
4510632638
4510532681
4510432726
4510362195
4510262244
4510162295
4510062348
450...

result:

ok 100000 numbers

Test #17:

score: 0
Accepted
time: 121ms
memory: 11748kb

input:

100000
BS 100000
SD 99999
B 99998
B 99997
DS 99996
D 99995
D 99994
BS 99993
BS 99992
D 99991
B 99990
B 99989
DB 99988
BS 99987
SD 99986
S 99985
BD 99984
DB 99983
S 99982
SB 99981
B 99980
B 99979
DS 99978
S 99977
D 99976
D 99975
S 99974
SB 99973
DB 99972
DS 99971
DS 99970
SD 99969
DB 99968
B 99967
SB...

output:

4448161436
4448061442
4447991688
4447921940
4447821950
4447721962
4447621976
4447521992
4447422010
4447322032
4447252292
4447182562
4447082588
4446982616
4446882646
4446782678
4446682712
4446582748
4446482786
4446382828
4446313112
4446243410
4446143456
4446043504
4445943554
4445843606
4445743660
444...

result:

ok 100000 numbers

Test #18:

score: 0
Accepted
time: 104ms
memory: 11736kb

input:

100000
S 100000
S 99999
S 99998
B 99997
D 99996
S 99995
S 99994
S 99993
B 99992
S 99991
D 99990
B 99989
S 99988
D 99987
S 99986
D 99985
D 99984
D 99983
S 99982
B 99981
B 99980
D 99979
S 99978
D 99977
S 99976
S 99975
D 99974
D 99973
B 99972
S 99971
B 99970
S 99969
B 99968
S 99967
B 99966
S 99965
D 99...

output:

4077343314
4077243318
4077143325
4077076417
4076976427
4076876439
4076776453
4076676470
4076609568
4076509588
4076409611
4076342714
4076242740
4076142768
4076042798
4075942830
4075842864
4075742900
4075642940
4075576055
4075509177
4075409221
4075309267
4075209315
4075109365
4075009417
4074909471
407...

result:

ok 100000 numbers