QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#343221#4253. RobotANIG80 272ms108624kbC++142.8kb2024-03-02 08:49:182024-03-02 08:49:18

Judging History

This is the latest submission verdict.

  • [2024-03-02 08:49:18]
  • Judged
  • Verdict: 80
  • Time: 272ms
  • Memory: 108624kb
  • [2024-03-02 08:49:18]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=6e5+5,inf=1e18;
struct xd{
    int a,b;
    int f(int x){
        return a*x+b;
    }
};
struct node{
    int lson,rson;
    xd mx,mn;
}p[N*100];
int idx;
int news(){
    idx++;
    p[idx].mx=(xd){0,-inf};
    p[idx].mn=(xd){0,inf};
    return idx;
}
void init(int x){
    if(!p[x].lson)p[x].lson=news();
    if(!p[x].rson)p[x].rson=news();
}
void add1(int x,int l,int r,xd sm){
    int mid=l+r>>1;
    if(p[x].mx.f(mid)<sm.f(mid))swap(sm,p[x].mx);
    if(l==r)return;
    if(p[x].mx.f(l)>sm.f(l)&&p[x].mx.f(r)>sm.f(r))return;
    init(x);
    if(p[x].mx.f(l)>sm.f(l))add1(p[x].rson,l,r,sm);
    if(p[x].mx.f(r)>sm.f(r))add1(p[x].lson,l,r,sm);
}
void add2(int x,int l,int r,xd sm){
    int mid=l+r>>1;
    if(p[x].mn.f(mid)>sm.f(mid))swap(sm,p[x].mn);
    if(l==r)return;
    if(p[x].mn.f(l)<sm.f(l)&&p[x].mn.f(r)<sm.f(r))return;
    init(x);
    if(p[x].mn.f(l)<sm.f(l))add2(p[x].rson,l,r,sm);
    if(p[x].mn.f(r)<sm.f(r))add2(p[x].lson,l,r,sm);
}
void add(int x,int l,int r,xd sm,int nl,int nr){
    if(l<=nl&&r>=nr){
        add1(x,nl,nr,sm);
        add2(x,nl,nr,sm);
        return;
    }
    init(x);
    int mid=nl+nr>>1;
    if(l<=mid)add(p[x].lson,l,r,sm,nl,mid);
    if(r>mid)add(p[x].rson,l,r,sm,mid+1,nr);
}
int gets1(int x,int d,int nl,int nr){
    if(!x)return -inf;
    if(nl==nr)return p[x].mx.f(d);
    int mid=nl+nr>>1;
    if(d<=mid)return max(gets1(p[x].lson,d,nl,mid),p[x].mx.f(d));
    else return max(gets1(p[x].rson,d,mid+1,nr),p[x].mx.f(d));
}
int gets2(int x,int d,int nl,int nr){
    if(!x)return inf;
    if(nl==nr)return p[x].mn.f(d);
    int mid=nl+nr>>1;
    if(d<=mid)return min(gets2(p[x].lson,d,nl,mid),p[x].mn.f(d));
    else return min(gets2(p[x].rson,d,mid+1,nr),p[x].mn.f(d));
}
int n,m,w[N],nxt[N],op[N],k[N],ks[N],dy[N],fst[N],nw[N];
signed main(){
    int tm[N];
    memset(tm,0,sizeof(tm));
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    news();
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>w[i],fst[i]=m+1;
    for(int i=1;i<=m;i++)nxt[i]=m+1;
    tm[m+1]=1e9;
    for(int i=1;i<=m;i++){
        string s;
        cin>>tm[i]>>s;
        if(s[0]=='c'){
            cin>>k[i]>>ks[i];
            if(dy[k[i]])nxt[dy[k[i]]]=i,dy[k[i]]=i;
            else fst[k[i]]=i,dy[k[i]]=i;
        }else op[i]=1;
    }
    for(int i=1;i<=n;i++)add(1,0,tm[fst[i]],(xd){0,w[i]},0,1e9);
    memset(dy,0,sizeof(dy));
    for(int i=1;i<=m;i++){
        if(op[i]){
            cout<<max(gets1(1,tm[i],0,1e9),-gets2(1,tm[i],0,1e9))<<"\n";
        }else{
            w[k[i]]=w[k[i]]+nw[k[i]]*(tm[i]-tm[dy[k[i]]]);
            nw[k[i]]=ks[i];dy[k[i]]=i;
            add(1,tm[i],tm[nxt[i]],(xd){ks[i],w[k[i]]-ks[i]*tm[i]},0,1e9);
        }
    }
}

詳細信息

Test #1:

score: 10
Accepted
time: 4ms
memory: 25164kb

input:

1999 2000
199 8854 -9513 9848 8434 -6615 -6770 4057 -9730 686 1586 6806 -511 -6328 -2250 2785 -4083 -3961 -711 9606 -9391 1041 -2844 -4889 993 -6955 -1982 -5300 9053 -5275 3950 -7977 -3652 8624 -716 -2013 -5229 -3686 -4602 -5031 9777 3802 491 -1354 -26 -3366 5285 5805 -7098 2233 -5967 -1318 -4553 63...

output:

86968438
360434523
838136414
913544563
969488608
1039885818
1109817781
1176515896
1251176599
1310476524
1510654766
1541254290
1558186230
1650869534
1683894444
1758250067
1785951331
1924000031
1993298953
2050165865
2254081337
2698178666
2750011758
2975976887
3216807039
3276625600
3332455240
335270492...

result:

ok 980 numbers

Test #2:

score: 10
Accepted
time: 4ms
memory: 28780kb

input:

1999 2000
6817 4353 -8180 954 -2553 1768 4986 -889 7032 -450 1234 -7637 9636 380 3607 -2296 -4881 -9025 2375 -1561 -8807 -3103 4385 8883 -2887 -1185 1960 6711 3478 -1056 -1717 -534 -9885 -6301 6011 5965 -9833 -5181 5329 3688 -6837 9023 64 -8326 3021 -7193 -9218 -4699 2354 -4720 1621 7361 -5233 9211 ...

output:

9999
6877566
19288910
55025322
173050121
235131941
259226075
297353495
487371773
672366281
768849281
844199177
852243863
1019578655
1077348683
1147535075
1160789843
1226398283
1261072277
1340915371
1413759421
1576022921
1664672671
1707990671
1778999971
1838562221
1977886871
2055492321
2318326971
235...

result:

ok 994 numbers

Test #3:

score: 10
Accepted
time: 128ms
memory: 96344kb

input:

99659 99039
-39276177 -64464963 -70081363 -443045475 -655771408 -409419920 -285052520 -312069074 -936205590 -10621715 -908116392 -660740279 -953732094 -591542519 -194540162 -139991296 -705911340 -778931920 -474438963 -518208970 -59960466 -981034014 -514533441 -217486555 -711871023 -615144144 -631291...

output:

999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
999962473
...

result:

ok 49673 numbers

Test #4:

score: 10
Accepted
time: 270ms
memory: 108624kb

input:

99572 579859
-100705410 -669206879 -432488010 -384767624 -742351351 -839681487 -968882737 -976751481 57117493 -959321678 -819420190 -325014480 -636525861 -382469947 -876672604 -213012287 -209210199 -875230847 -920443172 -731589320 -946964322 -789362448 -872075805 -828546101 51836817 -913319025 -8404...

output:

999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999981953
999964257
999964257
999964257
999964257
999964257
999964257
999964257
999964257
999959652
999959652
999959652
999959652
999959652
999959652
999959652
...

result:

ok 480125 numbers

Test #5:

score: 10
Accepted
time: 259ms
memory: 107684kb

input:

99320 577219
-525813544 -959369807 -718451747 -533082399 -787662356 -531754846 -650759294 -381852570 -979346470 -644489626 -425559804 -332888497 -203462089 -292970440 -958637976 -533593640 53499163 -331134986 -296264838 -806780896 -651958364 -547743072 -590243769 -75974484 -843772303 -367318307 -443...

output:

999992360
999992301
999992301
999992301
999992301
999992301
999992301
999992301
999992301
999992301
999991856
999987050
999984469
999983401
999980820
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
999978927
...

result:

ok 478076 numbers

Test #6:

score: 10
Accepted
time: 37ms
memory: 27644kb

input:

90498 99230
-33558917 30715649 81001133 -12438113 81315374 -70949846 -71212693 66569129 -16194103 -63049353 -79869090 97189792 61301532 53180861 -26423528 -30279746 32502058 7951680 -97121356 -5044511 -4113729 82719257 96311627 80260870 -29075735 -31473462 -27928703 81572824 -89715849 85470402 -5284...

output:

106294952
110163416
118535792
121674188
127268720
127704968
131859284
137162984
139716728
142361108
151520324
153761324
159719396
164628680
167492180
175844636
185014808
186302636
187034696
195742724
204533420
207048320
213505388
220715432
226279088
230415476
231647528
234046892
240457148
243998924
...

result:

ok 50858 numbers

Test #7:

score: 10
Accepted
time: 40ms
memory: 28568kb

input:

99124 99428
-29121705 73122072 14759978 -93785828 -52964748 50664810 -67789167 38732351 -57330970 48764999 -73647685 92261655 2267455 -21312555 -51092994 33675829 40607569 -85559394 -93024695 24124094 -45466947 -66665193 -99870070 -58435829 -56724651 -98854388 86610996 59912463 -27223092 85984568 94...

output:

106340510
113640698
116739890
122754640
124220766
127865950
128706392
135771234
142501746
142918910
150583550
157918850
162749170
171812008
180577442
182247096
185391794
194654232
201310892
209518444
210866742
213027412
213683098
222590248
225580256
231447498
239671018
249411498
250792730
251150014
...

result:

ok 57640 numbers

Test #8:

score: 10
Accepted
time: 112ms
memory: 93780kb

input:

99538 99031
-501609067 -774687736 -928215759 -477038092 -823455674 -871460165 -852927043 -704708804 -775793387 -521621627 -923721630 -811686668 -952989802 -841891941 -482572032 -509003031 -595485934 -831251065 -616219801 -580804479 -951849211 -783134298 -505096225 -625789647 -520043618 -798430551 -6...

output:

999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
999996555
1003771859
1005263811
1005937379
1006453139
1010634605
1020280585
1024269825
1028141905
1038638165
1047767365
1050993325
1054639205
1056180845
1067217665
1072164485
10888...

result:

ok 49771 numbers

Test #9:

score: 0
Wrong Answer
time: 251ms
memory: 61940kb

input:

99483 590517
-508842 -191922 830365 -321837 163127 -225035 -3981 -222030 721775 -244372 -342954 -692168 -156349 -853744 -606213 687012 -401837 -920227 -198596 -14000 -345069 -628969 -386394 -590462 97339 -974255 -551821 -623120 -673402 -567398 278012 511781 29418 -975780 -416796 902045 -565858 -2455...

output:

999991
999991
1007282
1017211
1027140
1056927
1056927
1076785
1076785
1076785
1086714
1096643
1146288
1146288
1156217
1186004
1195933
1195933
1195933
1195933
1205862
1205862
1235649
1235649
1245578
1245578
1245578
1245578
1245578
1255507
1265436
1265436
1285294
1295223
1305152
1315081
1325010
135479...

result:

wrong answer 1189th numbers differ - expected: '9994402', found: '9988089'

Test #10:

score: 0
Wrong Answer
time: 272ms
memory: 62372kb

input:

99801 597343
-32417 984702 259080 747296 807167 169192 454040 -426594 582296 321692 800273 962596 -968901 42596 -304443 574664 936854 271860 902411 38804 -688175 55613 31189 -930407 -544084 -164683 -442201 118338 -858190 -109300 682685 896380 -887043 357053 -908865 890420 -680972 632527 -106741 -668...

output:

999992
999992
999992
999992
1009495
1019216
1019216
1028937
1058100
1067821
1077542
1096984
1096984
1096984
1096984
1096984
1106705
1145589
1145589
1145589
1155310
1155310
1155310
1155310
1165031
1165031
1174752
1174752
1184473
1184473
1184473
1203915
1203915
1213636
1213636
1213636
1213636
1233078
...

result:

wrong answer 1192nd numbers differ - expected: '9977600', found: '9976202'