Submission #901614

# Submission time Handle Problem Language Result Execution time Memory
901614 2024-01-09T16:55:31 Z imarn Progression (NOI20_progression) C++14
68 / 100
715 ms 94412 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int N=3e5+5;
struct node{
    ll al,ar,mxl,mxr,mx,sz,dl,dr;
    node operator+(node b){
        node tmp;tmp.al=al;tmp.ar=b.ar;tmp.sz=sz+b.sz;
        tmp.mxl=max(mxl,1ll*2);tmp.mx=max({mx,b.mx,1ll*2});
        tmp.mxr=max(b.mxr,1ll*2);
        if(sz==0&&b.sz==0)return {0,0,0,0,0,0,0};
        else if(sz==0)return b;
        else if(b.sz==0)return {al,ar,mxl,mxr,mx,sz,dl,dr};
        else if(sz==1&&b.sz==1){
            tmp.mxl=2;tmp.mxr=2;tmp.mx=2;
            tmp.dl=b.al-ar,tmp.dr=b.al-ar;
        }
        else if(sz==1){
            if(b.al-ar==b.dl)tmp.mxl = max(tmp.mxl,1+b.mxl);
            if(b.al-ar==b.dl&&b.mxr==b.sz)tmp.mxr=max(tmp.mxr,1+b.mxr);
            if(b.al-ar==b.dl)tmp.mx=max(tmp.mx,1+b.mxl);
            tmp.dr=b.dr;tmp.dl=b.al-ar;
        }
        else if(b.sz==1){
            if(b.al-ar==dr&&mxl==sz)tmp.mxl = max({tmp.mxl,mxl+1});
            if(b.al-ar==dr)tmp.mxr=max(tmp.mxr,1+mxr);
            if(b.al-ar==dr)tmp.mx=max(tmp.mx,mxr+1);
            tmp.dr=b.al-ar;tmp.dl=dl;
        }
        else {
            if(dr==b.dl&&b.al-ar==dr&&mxl==sz)tmp.mxl = max({tmp.mxl,mxl+b.mxl});
            if(dr==b.dl&&b.al-ar==dr&&b.mxr==b.sz)tmp.mxr=max({tmp.mxr,mxr+b.mxr});
            if(dr==b.dl&&b.al-ar==dr)tmp.mx=max(tmp.mx,mxr+b.mxl);tmp.dl=dl,tmp.dr=b.dr;
            if(b.al-ar==dr&&mxl==sz)tmp.mxl = max({tmp.mxl,mxl+1});
            if(b.al-ar==b.dl&&b.mxr==b.sz)tmp.mxr=max({tmp.mxr,b.mxr+1});
            if(b.al-ar==dr)tmp.mx=max(tmp.mx,mxr+1);
            if(b.al-ar==b.dl)tmp.mx=max(tmp.mx,b.mxl+1);
        }return tmp;
    }
}t[4*N];
ll a[N];
pii lz[4*N];
bool lzc[4*N]{0};
void clr(int i,int l,int r){
    if(lzc[i]){
        lz[i]={0,0};
        t[i]={0,0,r-l+1,r-l+1,r-l+1,r-l+1,0,0};
        if(l<r){
            lzc[2*i]=lzc[2*i+1]=lzc[i];
            lz[2*i]=lz[2*i+1]={0,0};
        }lzc[i]=0;
    }
}
void push(int i,int l,int r){
    clr(i,l,r);
    t[i].al+=lz[i].f+l*lz[i].s;
    t[i].ar+=lz[i].f+r*lz[i].s;
    t[i].dl+=lz[i].s;t[i].dr+=lz[i].s;
    if(l<r){
        lz[2*i].f+=lz[i].f;lz[2*i].s+=lz[i].s;
        lz[2*i+1].f+=lz[i].f;lz[2*i+1].s+=lz[i].s;
    }lz[i]={0,0};
}
void build(int i,int l,int r){
    if(l==r)return void(t[i]={a[l],a[l],1,1,1,1,0,0});
    int m=(l+r)>>1;build(2*i,l,m);build(2*i+1,m+1,r);
    t[i]=t[2*i]+t[2*i+1];
}
node qr(int i,int l,int r,int tl,int tr){
    clr(i,l,r);push(i,l,r);
    if(r<tl||l>tr)return {0,0,0,0,0,0,0,0};
    if(r<=tr&&l>=tl)return t[i];
    int m=(l+r)>>1;
    return qr(2*i,l,m,tl,tr)+qr(2*i+1,m+1,r,tl,tr);
}
void upd(int i,int l,int r,int tl,int tr,ll S,ll L,ll C){
    clr(i,l,r);push(i,l,r);
    if(r<tl||l>tr)return;
    if(r<=tr&&l>=tl){
        lz[i].f+=S-L*C;lz[i].s+=C;push(i,l,r);
        return;
    }int m=(l+r)>>1;
    upd(2*i,l,m,tl,tr,S,L,C);upd(2*i+1,m+1,r,tl,tr,S,L,C);
    t[i]=t[2*i]+t[2*i+1];
}
void setzero(int i,int l,int r,int tl,int tr){
    clr(i,l,r);push(i,l,r);
    if(r<tl||l>tr)return;
    if(r<=tr&&l>=tl){
        lzc[i]=1;clr(i,l,r);return;
    }int m=(l+r)>>1;
    setzero(2*i,l,m,tl,tr);setzero(2*i+1,m+1,r,tl,tr);
    t[i]=t[2*i]+t[2*i+1];
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,q;cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=0;i<4*N;i++)lz[i]={0,0};
    build(1,1,n);
    while(q--){
        int x;cin>>x;
        if(x==1){
            ll l,r,s,c;cin>>l>>r>>s>>c;
            upd(1,1,n,l,r,s,l,c);
        }
        if(x==2){
            ll l,r,s,c;cin>>l>>r>>s>>c;
            setzero(1,1,n,l,r);
            upd(1,1,n,l,r,s,l,c);
        }
        if(x==3){
            int l,r;cin>>l>>r;
            cout<<qr(1,1,n,l,r).mx<<'\n';
        }
    }
}

Compilation message

Progression.cpp: In member function 'node node::operator+(node)':
Progression.cpp:38:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   38 |             if(dr==b.dl&&b.al-ar==dr)tmp.mx=max(tmp.mx,mxr+b.mxl);tmp.dl=dl,tmp.dr=b.dr;
      |             ^~
Progression.cpp:38:67: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   38 |             if(dr==b.dl&&b.al-ar==dr)tmp.mx=max(tmp.mx,mxr+b.mxl);tmp.dl=dl,tmp.dr=b.dr;
      |                                                                   ^~~
# Verdict Execution time Memory Grader output
1 Correct 119 ms 93772 KB Output is correct
2 Correct 75 ms 24912 KB Output is correct
3 Correct 70 ms 24912 KB Output is correct
4 Correct 69 ms 25072 KB Output is correct
5 Correct 69 ms 25116 KB Output is correct
6 Correct 70 ms 25168 KB Output is correct
7 Correct 75 ms 24904 KB Output is correct
8 Correct 5 ms 22876 KB Output is correct
9 Correct 5 ms 22884 KB Output is correct
10 Correct 5 ms 23036 KB Output is correct
11 Correct 122 ms 93516 KB Output is correct
12 Correct 121 ms 93520 KB Output is correct
13 Correct 120 ms 93780 KB Output is correct
14 Correct 116 ms 93732 KB Output is correct
15 Correct 117 ms 93520 KB Output is correct
16 Correct 124 ms 93548 KB Output is correct
17 Correct 116 ms 93444 KB Output is correct
18 Correct 117 ms 93532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 22876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 362 ms 93436 KB Output is correct
2 Correct 100 ms 25176 KB Output is correct
3 Correct 97 ms 25040 KB Output is correct
4 Correct 101 ms 25168 KB Output is correct
5 Correct 100 ms 25304 KB Output is correct
6 Correct 99 ms 25316 KB Output is correct
7 Correct 106 ms 24988 KB Output is correct
8 Correct 4 ms 22876 KB Output is correct
9 Correct 4 ms 22876 KB Output is correct
10 Correct 4 ms 22872 KB Output is correct
11 Correct 399 ms 92152 KB Output is correct
12 Correct 362 ms 93064 KB Output is correct
13 Correct 430 ms 92280 KB Output is correct
14 Correct 382 ms 92240 KB Output is correct
15 Correct 395 ms 93020 KB Output is correct
16 Correct 395 ms 93628 KB Output is correct
17 Correct 444 ms 93568 KB Output is correct
18 Correct 406 ms 93644 KB Output is correct
19 Correct 354 ms 92776 KB Output is correct
20 Correct 370 ms 93064 KB Output is correct
21 Correct 348 ms 92756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 601 ms 94412 KB Output is correct
2 Correct 137 ms 24916 KB Output is correct
3 Correct 155 ms 25428 KB Output is correct
4 Correct 138 ms 24916 KB Output is correct
5 Correct 163 ms 24916 KB Output is correct
6 Correct 148 ms 25156 KB Output is correct
7 Correct 139 ms 24836 KB Output is correct
8 Correct 3 ms 22876 KB Output is correct
9 Correct 4 ms 23036 KB Output is correct
10 Correct 4 ms 22876 KB Output is correct
11 Correct 589 ms 92396 KB Output is correct
12 Correct 562 ms 94060 KB Output is correct
13 Correct 607 ms 92240 KB Output is correct
14 Correct 602 ms 92372 KB Output is correct
15 Correct 541 ms 94320 KB Output is correct
16 Correct 583 ms 94096 KB Output is correct
17 Correct 626 ms 94112 KB Output is correct
18 Correct 601 ms 94184 KB Output is correct
19 Correct 580 ms 94084 KB Output is correct
20 Correct 599 ms 94008 KB Output is correct
21 Correct 572 ms 94044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 93436 KB Output is correct
2 Correct 100 ms 25176 KB Output is correct
3 Correct 97 ms 25040 KB Output is correct
4 Correct 101 ms 25168 KB Output is correct
5 Correct 100 ms 25304 KB Output is correct
6 Correct 99 ms 25316 KB Output is correct
7 Correct 106 ms 24988 KB Output is correct
8 Correct 4 ms 22876 KB Output is correct
9 Correct 4 ms 22876 KB Output is correct
10 Correct 4 ms 22872 KB Output is correct
11 Correct 399 ms 92152 KB Output is correct
12 Correct 362 ms 93064 KB Output is correct
13 Correct 430 ms 92280 KB Output is correct
14 Correct 382 ms 92240 KB Output is correct
15 Correct 395 ms 93020 KB Output is correct
16 Correct 395 ms 93628 KB Output is correct
17 Correct 444 ms 93568 KB Output is correct
18 Correct 406 ms 93644 KB Output is correct
19 Correct 354 ms 92776 KB Output is correct
20 Correct 370 ms 93064 KB Output is correct
21 Correct 348 ms 92756 KB Output is correct
22 Correct 635 ms 93872 KB Output is correct
23 Correct 125 ms 24884 KB Output is correct
24 Correct 126 ms 25184 KB Output is correct
25 Correct 127 ms 24944 KB Output is correct
26 Correct 135 ms 25012 KB Output is correct
27 Correct 127 ms 24912 KB Output is correct
28 Correct 145 ms 24900 KB Output is correct
29 Correct 4 ms 22876 KB Output is correct
30 Correct 4 ms 23028 KB Output is correct
31 Correct 4 ms 22876 KB Output is correct
32 Correct 637 ms 92476 KB Output is correct
33 Correct 659 ms 93664 KB Output is correct
34 Correct 684 ms 89240 KB Output is correct
35 Correct 709 ms 89216 KB Output is correct
36 Correct 596 ms 89468 KB Output is correct
37 Correct 589 ms 89332 KB Output is correct
38 Correct 610 ms 89212 KB Output is correct
39 Correct 715 ms 89328 KB Output is correct
40 Correct 666 ms 89204 KB Output is correct
41 Correct 713 ms 89228 KB Output is correct
42 Correct 675 ms 89092 KB Output is correct
43 Correct 612 ms 88976 KB Output is correct
44 Correct 669 ms 89076 KB Output is correct
45 Correct 622 ms 89188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 93772 KB Output is correct
2 Correct 75 ms 24912 KB Output is correct
3 Correct 70 ms 24912 KB Output is correct
4 Correct 69 ms 25072 KB Output is correct
5 Correct 69 ms 25116 KB Output is correct
6 Correct 70 ms 25168 KB Output is correct
7 Correct 75 ms 24904 KB Output is correct
8 Correct 5 ms 22876 KB Output is correct
9 Correct 5 ms 22884 KB Output is correct
10 Correct 5 ms 23036 KB Output is correct
11 Correct 122 ms 93516 KB Output is correct
12 Correct 121 ms 93520 KB Output is correct
13 Correct 120 ms 93780 KB Output is correct
14 Correct 116 ms 93732 KB Output is correct
15 Correct 117 ms 93520 KB Output is correct
16 Correct 124 ms 93548 KB Output is correct
17 Correct 116 ms 93444 KB Output is correct
18 Correct 117 ms 93532 KB Output is correct
19 Incorrect 5 ms 22876 KB Output isn't correct
20 Halted 0 ms 0 KB -