답안 #960331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960331 2024-04-10T09:22:53 Z boyliguanhan Progression (NOI20_progression) C++17
100 / 100
1516 ms 125156 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int Q=1e18;
struct Ln{
    int k,b;
    Ln(){k=b=0;}
    Ln(int x,int y){k=x,b=y;}
    friend Ln ad(Ln a, Ln b){return Ln(a.k+b.k,a.b+b.b);}
    int operator()(int x){
        return k*x+b;
    }
};
struct node{
    Ln V,S,A;
    node*lc,*rc;
    node(){A=Ln(),S=Ln(Q,0),lc=rc=0;}
    void mc(){
        if(!lc)lc=new node();
        if(!rc)rc=new node();
    }
    void push(){
        if(S.k!=Q) if(lc)
            lc->A=rc->A=Ln(),lc->S=rc->S=S,S.k=Q;
        if(A.k||A.b) if(lc)
            lc->A=ad(A,lc->A),rc->A=ad(A,rc->A),A=Ln();
    }
}*rt;
int lcq(node*rt,int l,int r,int pos){
    if(l-r) rt->mc();
    if(l==r)
        return ad(rt->A,rt->S)(pos);
    rt->push();
    if(l+r>>1<pos)
        return lcq(rt->rc,l+r+2>>1,r,pos);
    return lcq(rt->lc,l,l+r>>1,pos);
}
void lcua(node*rt,int l,int r,int tl,int tr,Ln x){
    if(l-r) rt->mc();
    if(l>tr||tl>r) return;
    if(tl<=l&&r<=tr)
        return rt->A=ad(rt->A,x),(l-r?rt->push():void());
    rt->push();
    lcua(rt->lc,l,l+r>>1,tl,tr,x);
    lcua(rt->rc,l+r+2>>1,r,tl,tr,x);
}
void lcus(node*rt,int l,int r,int tl,int tr,Ln x){
    if(l-r) rt->mc();
    if(l>tr||tl>r) return;
    if(tl<=l&&r<=tr)
        return rt->S=x,rt->A=Ln(),(l-r?rt->push():void());
    rt->push();
    lcus(rt->lc,l,l+r>>1,tl,tr,x);
    lcus(rt->rc,l+r+2>>1,r,tl,tr,x);
}
struct tp2{
    int FE,LE,ans,fans,lans,sz;
    tp2(int V,int s){FE=LE=V,ans=fans=lans=sz=s;}
    tp2(tp2 a,tp2 b){
        FE=(a.sz?a.FE:b.FE),LE=(b.sz?b.LE:a.LE);
        fans=(a.ans==a.sz&&FE==b.FE||!a.sz?a.sz+b.fans:a.fans);
        lans=(b.ans==b.sz&&LE==a.LE||!b.sz?b.sz+a.lans:b.lans);
        ans=max({a.ans,b.ans,(a.LE==b.FE)*(a.lans+b.fans)});
        sz=a.sz+b.sz;
    }
};
struct node2{
    tp2 V=tp2(0ll,1ll);
    int A=0,S=Q;
    node2(int v){V=tp2(v,1ll);}
    node2(){}
} T[1<<20];
void pd(int i,bool b){
    if(T[i].S!=Q){
        T[i].V=tp2(T[i].S,T[i].V.sz); if(b)
        T[i*2].S=T[i*2+1].S=T[i].S,T[i*2].A=T[i*2+1].A=0;
    }
    if(T[i].A){
        T[i].V.FE+=T[i].A,T[i].V.LE+=T[i].A; if(b)
        T[i*2].A+=T[i].A,T[i*2+1].A+=T[i].A;
    }
    T[i].A=0,T[i].S=Q;
}
tp2 segq(int i,int l,int r,int tl,int tr){
    pd(i,l-r);
    if(tl<=l&&r<=tr)
        return T[i].V;
    if(l>tr||tl>r)
        return tp2(0,0);
    return tp2(segq(i*2,l,l+r>>1,tl,tr),segq(i*2+1,l+r+2>>1,r,tl,tr));
}
void segua(int i,int l,int r,int tl,int tr,int X){
    pd(i,l-r);
    if(tl<=l&&r<=tr)
        return T[i].A+=X,pd(i,l-r);
    if(l>tr||tl>r) return;
    segua(i*2,l,l+r>>1,tl,tr,X);
    segua(i*2+1,l+r+2>>1,r,tl,tr,X);
    T[i].V=tp2(T[i*2].V,T[i*2+1].V);
}
void segus(int i,int l,int r,int tl,int tr,int X){
    pd(i,l-r);
    if(tl<=l&&r<=tr)
        return T[i].A=0,T[i].S=X,pd(i,l-r);
    if(l>tr||tl>r) return;
    segus(i*2,l,l+r>>1,tl,tr,X);
    segus(i*2+1,l+r+2>>1,r,tl,tr,X);
    T[i].V=tp2(T[i*2].V,T[i*2+1].V);
}
int bruh[5<<16],n;
void maintain(int id){
    segus(1,1,n-1,id,id,lcq(rt,1,n,id+1)-lcq(rt,1,n,id));
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int m;
    rt=new node();
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>bruh[i];
        lcus(rt,1,n,i,i,Ln(0,bruh[i]));
    }
    for(int i=1;i<n;i++)
        segus(1,1,n-1,i,i,bruh[i+1]-bruh[i]);
    while(m--){
        int t,l,r,s,c;
        cin>>t>>l>>r;
        if(t>2){
            cout<<(n-1?segq(1,1,n-1,l,r-1).ans+1:1)<<'\n';
            continue;
        }
        cin>>s>>c;
        if(t<2){
            lcua(rt,1,n,l,r,Ln(c,s-l*c));
            segua(1,1,n-1,l,r-1,c);
        } else {
            lcus(rt,1,n,l,r,Ln(c,s-l*c));
            segus(1,1,n-1,l,r-1,c);
        }
        if(l>1) maintain(l-1);
        if(r<n) maintain(r);
    }
}

Compilation message

Progression.cpp: In function 'long long int lcq(node*, long long int, long long int, long long int)':
Progression.cpp:34:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |     if(l+r>>1<pos)
      |        ~^~
Progression.cpp:35:30: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |         return lcq(rt->rc,l+r+2>>1,r,pos);
      |                           ~~~^~
Progression.cpp:36:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |     return lcq(rt->lc,l,l+r>>1,pos);
      |                         ~^~
Progression.cpp: In function 'void lcua(node*, long long int, long long int, long long int, long long int, Ln)':
Progression.cpp:44:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |     lcua(rt->lc,l,l+r>>1,tl,tr,x);
      |                   ~^~
Progression.cpp:45:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |     lcua(rt->rc,l+r+2>>1,r,tl,tr,x);
      |                 ~~~^~
Progression.cpp: In function 'void lcus(node*, long long int, long long int, long long int, long long int, Ln)':
Progression.cpp:53:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |     lcus(rt->lc,l,l+r>>1,tl,tr,x);
      |                   ~^~
Progression.cpp:54:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |     lcus(rt->rc,l+r+2>>1,r,tl,tr,x);
      |                 ~~~^~
Progression.cpp: In constructor 'tp2::tp2(tp2, tp2)':
Progression.cpp:61:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   61 |         fans=(a.ans==a.sz&&FE==b.FE||!a.sz?a.sz+b.fans:a.fans);
      |               ~~~~~~~~~~~^~~~~~~~~~
Progression.cpp:62:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   62 |         lans=(b.ans==b.sz&&LE==a.LE||!b.sz?b.sz+a.lans:b.lans);
      |               ~~~~~~~~~~~^~~~~~~~~~
Progression.cpp: In function 'tp2 segq(long long int, long long int, long long int, long long int, long long int)':
Progression.cpp:90:28: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |     return tp2(segq(i*2,l,l+r>>1,tl,tr),segq(i*2+1,l+r+2>>1,r,tl,tr));
      |                           ~^~
Progression.cpp:90:55: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   90 |     return tp2(segq(i*2,l,l+r>>1,tl,tr),segq(i*2+1,l+r+2>>1,r,tl,tr));
      |                                                    ~~~^~
Progression.cpp: In function 'void segua(long long int, long long int, long long int, long long int, long long int, long long int)':
Progression.cpp:97:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   97 |     segua(i*2,l,l+r>>1,tl,tr,X);
      |                 ~^~
Progression.cpp:98:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   98 |     segua(i*2+1,l+r+2>>1,r,tl,tr,X);
      |                 ~~~^~
Progression.cpp: In function 'void segus(long long int, long long int, long long int, long long int, long long int, long long int)':
Progression.cpp:106:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  106 |     segus(i*2,l,l+r>>1,tl,tr,X);
      |                 ~^~
Progression.cpp:107:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  107 |     segus(i*2+1,l+r+2>>1,r,tl,tr,X);
      |                 ~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 120564 KB Output is correct
2 Correct 73 ms 68496 KB Output is correct
3 Correct 80 ms 68432 KB Output is correct
4 Correct 73 ms 68444 KB Output is correct
5 Correct 74 ms 68524 KB Output is correct
6 Correct 74 ms 68520 KB Output is correct
7 Correct 73 ms 68364 KB Output is correct
8 Correct 10 ms 66396 KB Output is correct
9 Correct 10 ms 66396 KB Output is correct
10 Correct 10 ms 66472 KB Output is correct
11 Correct 273 ms 120704 KB Output is correct
12 Correct 269 ms 120404 KB Output is correct
13 Correct 260 ms 120740 KB Output is correct
14 Correct 256 ms 120832 KB Output is correct
15 Correct 262 ms 120476 KB Output is correct
16 Correct 277 ms 120640 KB Output is correct
17 Correct 271 ms 120500 KB Output is correct
18 Correct 278 ms 120460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 66652 KB Output is correct
2 Correct 11 ms 66396 KB Output is correct
3 Correct 11 ms 66396 KB Output is correct
4 Correct 11 ms 66236 KB Output is correct
5 Correct 11 ms 66392 KB Output is correct
6 Correct 10 ms 66396 KB Output is correct
7 Correct 10 ms 66396 KB Output is correct
8 Correct 14 ms 66472 KB Output is correct
9 Correct 12 ms 66396 KB Output is correct
10 Correct 13 ms 66632 KB Output is correct
11 Correct 11 ms 66604 KB Output is correct
12 Correct 12 ms 66652 KB Output is correct
13 Correct 11 ms 66396 KB Output is correct
14 Correct 11 ms 66396 KB Output is correct
15 Correct 12 ms 66652 KB Output is correct
16 Correct 12 ms 66652 KB Output is correct
17 Correct 12 ms 66652 KB Output is correct
18 Correct 12 ms 66652 KB Output is correct
19 Correct 12 ms 66396 KB Output is correct
20 Correct 11 ms 66348 KB Output is correct
21 Correct 11 ms 66320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 424 ms 119868 KB Output is correct
2 Correct 93 ms 68684 KB Output is correct
3 Correct 88 ms 68564 KB Output is correct
4 Correct 77 ms 68484 KB Output is correct
5 Correct 90 ms 68424 KB Output is correct
6 Correct 84 ms 68424 KB Output is correct
7 Correct 84 ms 68560 KB Output is correct
8 Correct 10 ms 66392 KB Output is correct
9 Correct 10 ms 66264 KB Output is correct
10 Correct 10 ms 66396 KB Output is correct
11 Correct 398 ms 119060 KB Output is correct
12 Correct 394 ms 119884 KB Output is correct
13 Correct 406 ms 119204 KB Output is correct
14 Correct 399 ms 119436 KB Output is correct
15 Correct 406 ms 119952 KB Output is correct
16 Correct 406 ms 120184 KB Output is correct
17 Correct 401 ms 120232 KB Output is correct
18 Correct 392 ms 120348 KB Output is correct
19 Correct 392 ms 119840 KB Output is correct
20 Correct 388 ms 119468 KB Output is correct
21 Correct 403 ms 119780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 944 ms 121204 KB Output is correct
2 Correct 152 ms 68692 KB Output is correct
3 Correct 161 ms 68536 KB Output is correct
4 Correct 153 ms 68528 KB Output is correct
5 Correct 156 ms 68688 KB Output is correct
6 Correct 161 ms 68268 KB Output is correct
7 Correct 155 ms 68436 KB Output is correct
8 Correct 10 ms 66348 KB Output is correct
9 Correct 10 ms 66396 KB Output is correct
10 Correct 11 ms 66396 KB Output is correct
11 Correct 945 ms 119096 KB Output is correct
12 Correct 986 ms 123576 KB Output is correct
13 Correct 925 ms 121048 KB Output is correct
14 Correct 931 ms 120988 KB Output is correct
15 Correct 914 ms 123508 KB Output is correct
16 Correct 942 ms 123416 KB Output is correct
17 Correct 954 ms 123644 KB Output is correct
18 Correct 1002 ms 123612 KB Output is correct
19 Correct 924 ms 123504 KB Output is correct
20 Correct 987 ms 121052 KB Output is correct
21 Correct 956 ms 121100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 424 ms 119868 KB Output is correct
2 Correct 93 ms 68684 KB Output is correct
3 Correct 88 ms 68564 KB Output is correct
4 Correct 77 ms 68484 KB Output is correct
5 Correct 90 ms 68424 KB Output is correct
6 Correct 84 ms 68424 KB Output is correct
7 Correct 84 ms 68560 KB Output is correct
8 Correct 10 ms 66392 KB Output is correct
9 Correct 10 ms 66264 KB Output is correct
10 Correct 10 ms 66396 KB Output is correct
11 Correct 398 ms 119060 KB Output is correct
12 Correct 394 ms 119884 KB Output is correct
13 Correct 406 ms 119204 KB Output is correct
14 Correct 399 ms 119436 KB Output is correct
15 Correct 406 ms 119952 KB Output is correct
16 Correct 406 ms 120184 KB Output is correct
17 Correct 401 ms 120232 KB Output is correct
18 Correct 392 ms 120348 KB Output is correct
19 Correct 392 ms 119840 KB Output is correct
20 Correct 388 ms 119468 KB Output is correct
21 Correct 403 ms 119780 KB Output is correct
22 Correct 1141 ms 120620 KB Output is correct
23 Correct 171 ms 68688 KB Output is correct
24 Correct 160 ms 68436 KB Output is correct
25 Correct 160 ms 68432 KB Output is correct
26 Correct 168 ms 68332 KB Output is correct
27 Correct 163 ms 68432 KB Output is correct
28 Correct 163 ms 68500 KB Output is correct
29 Correct 11 ms 66396 KB Output is correct
30 Correct 10 ms 66352 KB Output is correct
31 Correct 10 ms 66344 KB Output is correct
32 Correct 1166 ms 119424 KB Output is correct
33 Correct 1129 ms 120616 KB Output is correct
34 Correct 1159 ms 119280 KB Output is correct
35 Correct 1165 ms 119320 KB Output is correct
36 Correct 874 ms 119384 KB Output is correct
37 Correct 867 ms 119632 KB Output is correct
38 Correct 892 ms 119300 KB Output is correct
39 Correct 1183 ms 120672 KB Output is correct
40 Correct 1163 ms 120880 KB Output is correct
41 Correct 1185 ms 120904 KB Output is correct
42 Correct 1169 ms 120736 KB Output is correct
43 Correct 1120 ms 120588 KB Output is correct
44 Correct 1173 ms 122240 KB Output is correct
45 Correct 1257 ms 122668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 288 ms 120564 KB Output is correct
2 Correct 73 ms 68496 KB Output is correct
3 Correct 80 ms 68432 KB Output is correct
4 Correct 73 ms 68444 KB Output is correct
5 Correct 74 ms 68524 KB Output is correct
6 Correct 74 ms 68520 KB Output is correct
7 Correct 73 ms 68364 KB Output is correct
8 Correct 10 ms 66396 KB Output is correct
9 Correct 10 ms 66396 KB Output is correct
10 Correct 10 ms 66472 KB Output is correct
11 Correct 273 ms 120704 KB Output is correct
12 Correct 269 ms 120404 KB Output is correct
13 Correct 260 ms 120740 KB Output is correct
14 Correct 256 ms 120832 KB Output is correct
15 Correct 262 ms 120476 KB Output is correct
16 Correct 277 ms 120640 KB Output is correct
17 Correct 271 ms 120500 KB Output is correct
18 Correct 278 ms 120460 KB Output is correct
19 Correct 12 ms 66652 KB Output is correct
20 Correct 11 ms 66396 KB Output is correct
21 Correct 11 ms 66396 KB Output is correct
22 Correct 11 ms 66236 KB Output is correct
23 Correct 11 ms 66392 KB Output is correct
24 Correct 10 ms 66396 KB Output is correct
25 Correct 10 ms 66396 KB Output is correct
26 Correct 14 ms 66472 KB Output is correct
27 Correct 12 ms 66396 KB Output is correct
28 Correct 13 ms 66632 KB Output is correct
29 Correct 11 ms 66604 KB Output is correct
30 Correct 12 ms 66652 KB Output is correct
31 Correct 11 ms 66396 KB Output is correct
32 Correct 11 ms 66396 KB Output is correct
33 Correct 12 ms 66652 KB Output is correct
34 Correct 12 ms 66652 KB Output is correct
35 Correct 12 ms 66652 KB Output is correct
36 Correct 12 ms 66652 KB Output is correct
37 Correct 12 ms 66396 KB Output is correct
38 Correct 11 ms 66348 KB Output is correct
39 Correct 11 ms 66320 KB Output is correct
40 Correct 424 ms 119868 KB Output is correct
41 Correct 93 ms 68684 KB Output is correct
42 Correct 88 ms 68564 KB Output is correct
43 Correct 77 ms 68484 KB Output is correct
44 Correct 90 ms 68424 KB Output is correct
45 Correct 84 ms 68424 KB Output is correct
46 Correct 84 ms 68560 KB Output is correct
47 Correct 10 ms 66392 KB Output is correct
48 Correct 10 ms 66264 KB Output is correct
49 Correct 10 ms 66396 KB Output is correct
50 Correct 398 ms 119060 KB Output is correct
51 Correct 394 ms 119884 KB Output is correct
52 Correct 406 ms 119204 KB Output is correct
53 Correct 399 ms 119436 KB Output is correct
54 Correct 406 ms 119952 KB Output is correct
55 Correct 406 ms 120184 KB Output is correct
56 Correct 401 ms 120232 KB Output is correct
57 Correct 392 ms 120348 KB Output is correct
58 Correct 392 ms 119840 KB Output is correct
59 Correct 388 ms 119468 KB Output is correct
60 Correct 403 ms 119780 KB Output is correct
61 Correct 944 ms 121204 KB Output is correct
62 Correct 152 ms 68692 KB Output is correct
63 Correct 161 ms 68536 KB Output is correct
64 Correct 153 ms 68528 KB Output is correct
65 Correct 156 ms 68688 KB Output is correct
66 Correct 161 ms 68268 KB Output is correct
67 Correct 155 ms 68436 KB Output is correct
68 Correct 10 ms 66348 KB Output is correct
69 Correct 10 ms 66396 KB Output is correct
70 Correct 11 ms 66396 KB Output is correct
71 Correct 945 ms 119096 KB Output is correct
72 Correct 986 ms 123576 KB Output is correct
73 Correct 925 ms 121048 KB Output is correct
74 Correct 931 ms 120988 KB Output is correct
75 Correct 914 ms 123508 KB Output is correct
76 Correct 942 ms 123416 KB Output is correct
77 Correct 954 ms 123644 KB Output is correct
78 Correct 1002 ms 123612 KB Output is correct
79 Correct 924 ms 123504 KB Output is correct
80 Correct 987 ms 121052 KB Output is correct
81 Correct 956 ms 121100 KB Output is correct
82 Correct 1141 ms 120620 KB Output is correct
83 Correct 171 ms 68688 KB Output is correct
84 Correct 160 ms 68436 KB Output is correct
85 Correct 160 ms 68432 KB Output is correct
86 Correct 168 ms 68332 KB Output is correct
87 Correct 163 ms 68432 KB Output is correct
88 Correct 163 ms 68500 KB Output is correct
89 Correct 11 ms 66396 KB Output is correct
90 Correct 10 ms 66352 KB Output is correct
91 Correct 10 ms 66344 KB Output is correct
92 Correct 1166 ms 119424 KB Output is correct
93 Correct 1129 ms 120616 KB Output is correct
94 Correct 1159 ms 119280 KB Output is correct
95 Correct 1165 ms 119320 KB Output is correct
96 Correct 874 ms 119384 KB Output is correct
97 Correct 867 ms 119632 KB Output is correct
98 Correct 892 ms 119300 KB Output is correct
99 Correct 1183 ms 120672 KB Output is correct
100 Correct 1163 ms 120880 KB Output is correct
101 Correct 1185 ms 120904 KB Output is correct
102 Correct 1169 ms 120736 KB Output is correct
103 Correct 1120 ms 120588 KB Output is correct
104 Correct 1173 ms 122240 KB Output is correct
105 Correct 1257 ms 122668 KB Output is correct
106 Correct 1484 ms 123820 KB Output is correct
107 Correct 193 ms 69220 KB Output is correct
108 Correct 195 ms 69292 KB Output is correct
109 Correct 209 ms 69308 KB Output is correct
110 Correct 13 ms 66396 KB Output is correct
111 Correct 11 ms 66396 KB Output is correct
112 Correct 11 ms 66256 KB Output is correct
113 Correct 1221 ms 123236 KB Output is correct
114 Correct 1224 ms 122828 KB Output is correct
115 Correct 1162 ms 123040 KB Output is correct
116 Correct 1156 ms 122892 KB Output is correct
117 Correct 1418 ms 123872 KB Output is correct
118 Correct 1175 ms 123040 KB Output is correct
119 Correct 1165 ms 122656 KB Output is correct
120 Correct 435 ms 122328 KB Output is correct
121 Correct 463 ms 122220 KB Output is correct
122 Correct 427 ms 122052 KB Output is correct
123 Correct 407 ms 121392 KB Output is correct
124 Correct 439 ms 121344 KB Output is correct
125 Correct 446 ms 121304 KB Output is correct
126 Correct 1516 ms 121332 KB Output is correct
127 Correct 1455 ms 121120 KB Output is correct
128 Correct 1502 ms 124016 KB Output is correct
129 Correct 1450 ms 121276 KB Output is correct
130 Correct 964 ms 121388 KB Output is correct
131 Correct 963 ms 121544 KB Output is correct
132 Correct 976 ms 121576 KB Output is correct
133 Correct 1465 ms 123832 KB Output is correct
134 Correct 1481 ms 123936 KB Output is correct
135 Correct 1502 ms 125156 KB Output is correct
136 Correct 205 ms 69808 KB Output is correct
137 Correct 199 ms 69724 KB Output is correct
138 Correct 208 ms 69660 KB Output is correct