Submission #647653

# Submission time Handle Problem Language Result Execution time Memory
647653 2022-10-03T13:41:40 Z mosiashvililuka Measures (CEOI22_measures) C++14
100 / 100
662 ms 34764 KB
#include<bits/stdc++.h>
using namespace std;
const long long N=999999999999999999LL;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,NN,M,D,f[400009],pas,fen[400009],seg[2000009],segmn[2000009],segmx[2000009],seg2[2000009],l,r,z,za;
map <long long, long long> m;
map <long long, long long>::iterator IT;
void updfen(long long q, long long w){
    while(q<=400003){
        fen[q]+=w;
        q=q+(q&(-q));
    }
}
long long readfen(long long q){
    long long sm=0;
    while(q>0){
        sm+=fen[q];
        q=q-(q&(-q));
    }
    return sm;
}
void GETrr(long long rr){
    segmx[rr]=max(segmx[rr*2],segmx[rr*2+1]);
    segmn[rr]=min(segmn[rr*2],segmn[rr*2+1]);

    seg[rr]=max(seg[rr*2],seg[rr*2+1]);
    seg[rr]=max(seg[rr],segmx[rr*2]-segmn[rr*2+1]);
}
void UP(long long rr){
    rr/=2;
    while(rr!=0){
        GETrr(rr);
        rr/=2;
    }
}
void pushdown(long long q, long long w, long long rr){
    if(q!=w){
        seg2[rr*2]+=seg2[rr];
        seg2[rr*2+1]+=seg2[rr];
    }
    segmn[rr]+=seg2[rr];segmx[rr]+=seg2[rr];
    seg2[rr]=0;
}
void upd(long long q, long long w, long long rr){
    pushdown(q,w,rr);
    if(q>r||w<l) return;
    if(q>=l&&w<=r){
        seg2[rr]+=z;
        pushdown(q,w,rr);
        return;
    }
    upd(q,(q+w)/2,rr*2);
    upd((q+w)/2+1,w,rr*2+1);
    GETrr(rr);
}
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>NN>>M>>D;a=NN+M;
    for(i=1; i<=a; i++){
        cin>>f[i];
        m[f[i]]++;
    }
    za=1;
    while(za<a) za*=2;
    for(i=0; i<=za*2+1; i++){
        segmn[i]=N;segmx[i]=-N;seg[i]=0;
    }
    zx=0;
    for(IT=m.begin(); IT!=m.end(); IT++){
        xc=(*IT).second;
        (*IT).second=zx;zx+=xc;
    }
    for(ii=1; ii<=a; ii++){
        m[f[ii]]++;
        i=m[f[ii]];
        //
        l=i;r=i;z=0;
        upd(1,za,1);
        c=readfen(i);updfen(i,1);
        segmn[za+i-1]=segmx[za+i-1]=f[ii]-c*D;seg[za+i-1]=0;
        UP(za+i-1);
        //
        l=i;r=a;z=-D;
        upd(1,za,1);
        //
        pushdown(1,za,1);
        pas=seg[1];
        if(ii<=NN) continue;
        if(pas%2==0){
            cout<<pas/2<<" ";
        }else{
            cout<<pas/2<<".5 ";
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 680 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 3 ms 596 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 680 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 567 ms 31496 KB Output is correct
10 Correct 497 ms 31492 KB Output is correct
11 Correct 204 ms 18908 KB Output is correct
12 Correct 297 ms 31480 KB Output is correct
13 Correct 285 ms 31488 KB Output is correct
14 Correct 311 ms 31432 KB Output is correct
15 Correct 562 ms 31500 KB Output is correct
16 Correct 293 ms 31388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 32508 KB Output is correct
2 Correct 310 ms 34452 KB Output is correct
3 Correct 200 ms 21884 KB Output is correct
4 Correct 302 ms 32360 KB Output is correct
5 Correct 292 ms 33520 KB Output is correct
6 Correct 297 ms 32732 KB Output is correct
7 Correct 290 ms 33588 KB Output is correct
8 Correct 284 ms 32404 KB Output is correct
9 Correct 299 ms 32276 KB Output is correct
10 Correct 289 ms 34764 KB Output is correct
11 Correct 295 ms 33036 KB Output is correct
12 Correct 298 ms 34064 KB Output is correct
13 Correct 298 ms 32316 KB Output is correct
14 Correct 296 ms 34208 KB Output is correct
15 Correct 292 ms 34132 KB Output is correct
16 Correct 314 ms 32204 KB Output is correct
17 Correct 285 ms 33556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 292 ms 32508 KB Output is correct
2 Correct 310 ms 34452 KB Output is correct
3 Correct 200 ms 21884 KB Output is correct
4 Correct 302 ms 32360 KB Output is correct
5 Correct 292 ms 33520 KB Output is correct
6 Correct 297 ms 32732 KB Output is correct
7 Correct 290 ms 33588 KB Output is correct
8 Correct 284 ms 32404 KB Output is correct
9 Correct 299 ms 32276 KB Output is correct
10 Correct 289 ms 34764 KB Output is correct
11 Correct 295 ms 33036 KB Output is correct
12 Correct 298 ms 34064 KB Output is correct
13 Correct 298 ms 32316 KB Output is correct
14 Correct 296 ms 34208 KB Output is correct
15 Correct 292 ms 34132 KB Output is correct
16 Correct 314 ms 32204 KB Output is correct
17 Correct 285 ms 33556 KB Output is correct
18 Correct 662 ms 32652 KB Output is correct
19 Correct 515 ms 34364 KB Output is correct
20 Correct 214 ms 21916 KB Output is correct
21 Correct 303 ms 32436 KB Output is correct
22 Correct 466 ms 32736 KB Output is correct
23 Correct 278 ms 32584 KB Output is correct
24 Correct 596 ms 33052 KB Output is correct
25 Correct 296 ms 32160 KB Output is correct
26 Correct 549 ms 32244 KB Output is correct
27 Correct 591 ms 34716 KB Output is correct
28 Correct 427 ms 32696 KB Output is correct
29 Correct 461 ms 34000 KB Output is correct
30 Correct 301 ms 32096 KB Output is correct
31 Correct 306 ms 34200 KB Output is correct
32 Correct 291 ms 34144 KB Output is correct
33 Correct 590 ms 32244 KB Output is correct
34 Correct 293 ms 33504 KB Output is correct