답안 #901615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
901615 2024-01-09T16:59:30 Z imarn Progression (NOI20_progression) C++14
100 / 100
936 ms 99392 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]){
        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){
    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){
    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){
    push(i,l,r);
    if(r<tl||l>tr)return;
    if(r<=tr&&l>=tl){
        lzc[i]=1;push(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;
      |                                                                   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 89168 KB Output is correct
2 Correct 68 ms 23124 KB Output is correct
3 Correct 67 ms 23264 KB Output is correct
4 Correct 75 ms 23228 KB Output is correct
5 Correct 67 ms 23200 KB Output is correct
6 Correct 68 ms 23148 KB Output is correct
7 Correct 79 ms 23128 KB Output is correct
8 Correct 4 ms 22872 KB Output is correct
9 Correct 5 ms 22872 KB Output is correct
10 Correct 4 ms 22876 KB Output is correct
11 Correct 116 ms 89188 KB Output is correct
12 Correct 119 ms 89168 KB Output is correct
13 Correct 123 ms 89388 KB Output is correct
14 Correct 113 ms 89428 KB Output is correct
15 Correct 114 ms 89476 KB Output is correct
16 Correct 115 ms 89168 KB Output is correct
17 Correct 125 ms 89212 KB Output is correct
18 Correct 118 ms 89204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 22872 KB Output is correct
2 Correct 4 ms 22876 KB Output is correct
3 Correct 4 ms 22876 KB Output is correct
4 Correct 4 ms 22876 KB Output is correct
5 Correct 4 ms 23000 KB Output is correct
6 Correct 4 ms 22876 KB Output is correct
7 Correct 4 ms 22876 KB Output is correct
8 Correct 5 ms 22876 KB Output is correct
9 Correct 5 ms 22876 KB Output is correct
10 Correct 4 ms 22876 KB Output is correct
11 Correct 5 ms 22876 KB Output is correct
12 Correct 5 ms 23024 KB Output is correct
13 Correct 4 ms 22876 KB Output is correct
14 Correct 4 ms 22872 KB Output is correct
15 Correct 5 ms 23004 KB Output is correct
16 Correct 5 ms 23064 KB Output is correct
17 Correct 5 ms 22872 KB Output is correct
18 Correct 5 ms 22876 KB Output is correct
19 Correct 4 ms 22872 KB Output is correct
20 Correct 4 ms 22876 KB Output is correct
21 Correct 4 ms 22872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 335 ms 89744 KB Output is correct
2 Correct 98 ms 23376 KB Output is correct
3 Correct 97 ms 23512 KB Output is correct
4 Correct 97 ms 23572 KB Output is correct
5 Correct 97 ms 23636 KB Output is correct
6 Correct 98 ms 23540 KB Output is correct
7 Correct 115 ms 23476 KB Output is correct
8 Correct 3 ms 22872 KB Output is correct
9 Correct 3 ms 22876 KB Output is correct
10 Correct 3 ms 22876 KB Output is correct
11 Correct 391 ms 89624 KB Output is correct
12 Correct 325 ms 89724 KB Output is correct
13 Correct 409 ms 89332 KB Output is correct
14 Correct 395 ms 89236 KB Output is correct
15 Correct 326 ms 89680 KB Output is correct
16 Correct 410 ms 90044 KB Output is correct
17 Correct 385 ms 89940 KB Output is correct
18 Correct 400 ms 89940 KB Output is correct
19 Correct 340 ms 89168 KB Output is correct
20 Correct 345 ms 89428 KB Output is correct
21 Correct 344 ms 89172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 591 ms 89072 KB Output is correct
2 Correct 138 ms 23124 KB Output is correct
3 Correct 138 ms 23124 KB Output is correct
4 Correct 137 ms 23072 KB Output is correct
5 Correct 140 ms 23120 KB Output is correct
6 Correct 139 ms 23124 KB Output is correct
7 Correct 144 ms 23636 KB Output is correct
8 Correct 4 ms 22876 KB Output is correct
9 Correct 4 ms 22876 KB Output is correct
10 Correct 3 ms 22876 KB Output is correct
11 Correct 554 ms 88912 KB Output is correct
12 Correct 574 ms 89004 KB Output is correct
13 Correct 552 ms 89204 KB Output is correct
14 Correct 563 ms 89192 KB Output is correct
15 Correct 517 ms 88664 KB Output is correct
16 Correct 579 ms 88792 KB Output is correct
17 Correct 578 ms 89156 KB Output is correct
18 Correct 566 ms 88948 KB Output is correct
19 Correct 549 ms 89044 KB Output is correct
20 Correct 547 ms 88912 KB Output is correct
21 Correct 547 ms 88800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 335 ms 89744 KB Output is correct
2 Correct 98 ms 23376 KB Output is correct
3 Correct 97 ms 23512 KB Output is correct
4 Correct 97 ms 23572 KB Output is correct
5 Correct 97 ms 23636 KB Output is correct
6 Correct 98 ms 23540 KB Output is correct
7 Correct 115 ms 23476 KB Output is correct
8 Correct 3 ms 22872 KB Output is correct
9 Correct 3 ms 22876 KB Output is correct
10 Correct 3 ms 22876 KB Output is correct
11 Correct 391 ms 89624 KB Output is correct
12 Correct 325 ms 89724 KB Output is correct
13 Correct 409 ms 89332 KB Output is correct
14 Correct 395 ms 89236 KB Output is correct
15 Correct 326 ms 89680 KB Output is correct
16 Correct 410 ms 90044 KB Output is correct
17 Correct 385 ms 89940 KB Output is correct
18 Correct 400 ms 89940 KB Output is correct
19 Correct 340 ms 89168 KB Output is correct
20 Correct 345 ms 89428 KB Output is correct
21 Correct 344 ms 89172 KB Output is correct
22 Correct 608 ms 88916 KB Output is correct
23 Correct 125 ms 23376 KB Output is correct
24 Correct 122 ms 23104 KB Output is correct
25 Correct 122 ms 23124 KB Output is correct
26 Correct 125 ms 23124 KB Output is correct
27 Correct 128 ms 23120 KB Output is correct
28 Correct 126 ms 23124 KB Output is correct
29 Correct 3 ms 22876 KB Output is correct
30 Correct 4 ms 22876 KB Output is correct
31 Correct 3 ms 22876 KB Output is correct
32 Correct 638 ms 88936 KB Output is correct
33 Correct 598 ms 89300 KB Output is correct
34 Correct 617 ms 89080 KB Output is correct
35 Correct 622 ms 89180 KB Output is correct
36 Correct 572 ms 89236 KB Output is correct
37 Correct 570 ms 89168 KB Output is correct
38 Correct 586 ms 89296 KB Output is correct
39 Correct 601 ms 88968 KB Output is correct
40 Correct 658 ms 89348 KB Output is correct
41 Correct 631 ms 89172 KB Output is correct
42 Correct 640 ms 89148 KB Output is correct
43 Correct 622 ms 88916 KB Output is correct
44 Correct 605 ms 89168 KB Output is correct
45 Correct 612 ms 88916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 89168 KB Output is correct
2 Correct 68 ms 23124 KB Output is correct
3 Correct 67 ms 23264 KB Output is correct
4 Correct 75 ms 23228 KB Output is correct
5 Correct 67 ms 23200 KB Output is correct
6 Correct 68 ms 23148 KB Output is correct
7 Correct 79 ms 23128 KB Output is correct
8 Correct 4 ms 22872 KB Output is correct
9 Correct 5 ms 22872 KB Output is correct
10 Correct 4 ms 22876 KB Output is correct
11 Correct 116 ms 89188 KB Output is correct
12 Correct 119 ms 89168 KB Output is correct
13 Correct 123 ms 89388 KB Output is correct
14 Correct 113 ms 89428 KB Output is correct
15 Correct 114 ms 89476 KB Output is correct
16 Correct 115 ms 89168 KB Output is correct
17 Correct 125 ms 89212 KB Output is correct
18 Correct 118 ms 89204 KB Output is correct
19 Correct 5 ms 22872 KB Output is correct
20 Correct 4 ms 22876 KB Output is correct
21 Correct 4 ms 22876 KB Output is correct
22 Correct 4 ms 22876 KB Output is correct
23 Correct 4 ms 23000 KB Output is correct
24 Correct 4 ms 22876 KB Output is correct
25 Correct 4 ms 22876 KB Output is correct
26 Correct 5 ms 22876 KB Output is correct
27 Correct 5 ms 22876 KB Output is correct
28 Correct 4 ms 22876 KB Output is correct
29 Correct 5 ms 22876 KB Output is correct
30 Correct 5 ms 23024 KB Output is correct
31 Correct 4 ms 22876 KB Output is correct
32 Correct 4 ms 22872 KB Output is correct
33 Correct 5 ms 23004 KB Output is correct
34 Correct 5 ms 23064 KB Output is correct
35 Correct 5 ms 22872 KB Output is correct
36 Correct 5 ms 22876 KB Output is correct
37 Correct 4 ms 22872 KB Output is correct
38 Correct 4 ms 22876 KB Output is correct
39 Correct 4 ms 22872 KB Output is correct
40 Correct 335 ms 89744 KB Output is correct
41 Correct 98 ms 23376 KB Output is correct
42 Correct 97 ms 23512 KB Output is correct
43 Correct 97 ms 23572 KB Output is correct
44 Correct 97 ms 23636 KB Output is correct
45 Correct 98 ms 23540 KB Output is correct
46 Correct 115 ms 23476 KB Output is correct
47 Correct 3 ms 22872 KB Output is correct
48 Correct 3 ms 22876 KB Output is correct
49 Correct 3 ms 22876 KB Output is correct
50 Correct 391 ms 89624 KB Output is correct
51 Correct 325 ms 89724 KB Output is correct
52 Correct 409 ms 89332 KB Output is correct
53 Correct 395 ms 89236 KB Output is correct
54 Correct 326 ms 89680 KB Output is correct
55 Correct 410 ms 90044 KB Output is correct
56 Correct 385 ms 89940 KB Output is correct
57 Correct 400 ms 89940 KB Output is correct
58 Correct 340 ms 89168 KB Output is correct
59 Correct 345 ms 89428 KB Output is correct
60 Correct 344 ms 89172 KB Output is correct
61 Correct 591 ms 89072 KB Output is correct
62 Correct 138 ms 23124 KB Output is correct
63 Correct 138 ms 23124 KB Output is correct
64 Correct 137 ms 23072 KB Output is correct
65 Correct 140 ms 23120 KB Output is correct
66 Correct 139 ms 23124 KB Output is correct
67 Correct 144 ms 23636 KB Output is correct
68 Correct 4 ms 22876 KB Output is correct
69 Correct 4 ms 22876 KB Output is correct
70 Correct 3 ms 22876 KB Output is correct
71 Correct 554 ms 88912 KB Output is correct
72 Correct 574 ms 89004 KB Output is correct
73 Correct 552 ms 89204 KB Output is correct
74 Correct 563 ms 89192 KB Output is correct
75 Correct 517 ms 88664 KB Output is correct
76 Correct 579 ms 88792 KB Output is correct
77 Correct 578 ms 89156 KB Output is correct
78 Correct 566 ms 88948 KB Output is correct
79 Correct 549 ms 89044 KB Output is correct
80 Correct 547 ms 88912 KB Output is correct
81 Correct 547 ms 88800 KB Output is correct
82 Correct 608 ms 88916 KB Output is correct
83 Correct 125 ms 23376 KB Output is correct
84 Correct 122 ms 23104 KB Output is correct
85 Correct 122 ms 23124 KB Output is correct
86 Correct 125 ms 23124 KB Output is correct
87 Correct 128 ms 23120 KB Output is correct
88 Correct 126 ms 23124 KB Output is correct
89 Correct 3 ms 22876 KB Output is correct
90 Correct 4 ms 22876 KB Output is correct
91 Correct 3 ms 22876 KB Output is correct
92 Correct 638 ms 88936 KB Output is correct
93 Correct 598 ms 89300 KB Output is correct
94 Correct 617 ms 89080 KB Output is correct
95 Correct 622 ms 89180 KB Output is correct
96 Correct 572 ms 89236 KB Output is correct
97 Correct 570 ms 89168 KB Output is correct
98 Correct 586 ms 89296 KB Output is correct
99 Correct 601 ms 88968 KB Output is correct
100 Correct 658 ms 89348 KB Output is correct
101 Correct 631 ms 89172 KB Output is correct
102 Correct 640 ms 89148 KB Output is correct
103 Correct 622 ms 88916 KB Output is correct
104 Correct 605 ms 89168 KB Output is correct
105 Correct 612 ms 88916 KB Output is correct
106 Correct 888 ms 99152 KB Output is correct
107 Correct 165 ms 26292 KB Output is correct
108 Correct 166 ms 26364 KB Output is correct
109 Correct 166 ms 26412 KB Output is correct
110 Correct 4 ms 22876 KB Output is correct
111 Correct 4 ms 22872 KB Output is correct
112 Correct 4 ms 22876 KB Output is correct
113 Correct 644 ms 98028 KB Output is correct
114 Correct 643 ms 97976 KB Output is correct
115 Correct 659 ms 97796 KB Output is correct
116 Correct 610 ms 97872 KB Output is correct
117 Correct 871 ms 98900 KB Output is correct
118 Correct 615 ms 97904 KB Output is correct
119 Correct 610 ms 97876 KB Output is correct
120 Correct 389 ms 96500 KB Output is correct
121 Correct 408 ms 96340 KB Output is correct
122 Correct 385 ms 96424 KB Output is correct
123 Correct 350 ms 95680 KB Output is correct
124 Correct 347 ms 95628 KB Output is correct
125 Correct 349 ms 95660 KB Output is correct
126 Correct 936 ms 95608 KB Output is correct
127 Correct 878 ms 95784 KB Output is correct
128 Correct 899 ms 99140 KB Output is correct
129 Correct 872 ms 95828 KB Output is correct
130 Correct 699 ms 95672 KB Output is correct
131 Correct 699 ms 95828 KB Output is correct
132 Correct 692 ms 95620 KB Output is correct
133 Correct 886 ms 99152 KB Output is correct
134 Correct 907 ms 99392 KB Output is correct
135 Correct 887 ms 99172 KB Output is correct
136 Correct 172 ms 26192 KB Output is correct
137 Correct 166 ms 26436 KB Output is correct
138 Correct 170 ms 26400 KB Output is correct