답안 #960328

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960328 2024-04-10T09:20:32 Z vjudge1 Progression (NOI20_progression) C++17
100 / 100
1470 ms 126268 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 300 ms 120440 KB Output is correct
2 Correct 72 ms 68508 KB Output is correct
3 Correct 77 ms 68420 KB Output is correct
4 Correct 81 ms 68456 KB Output is correct
5 Correct 89 ms 68432 KB Output is correct
6 Correct 78 ms 68664 KB Output is correct
7 Correct 101 ms 68496 KB Output is correct
8 Correct 13 ms 66476 KB Output is correct
9 Correct 13 ms 66336 KB Output is correct
10 Correct 11 ms 66648 KB Output is correct
11 Correct 284 ms 124224 KB Output is correct
12 Correct 291 ms 124124 KB Output is correct
13 Correct 287 ms 124324 KB Output is correct
14 Correct 295 ms 124588 KB Output is correct
15 Correct 297 ms 124420 KB Output is correct
16 Correct 290 ms 124068 KB Output is correct
17 Correct 288 ms 124128 KB Output is correct
18 Correct 303 ms 124168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 66664 KB Output is correct
2 Correct 13 ms 66392 KB Output is correct
3 Correct 12 ms 66248 KB Output is correct
4 Correct 12 ms 66396 KB Output is correct
5 Correct 12 ms 66248 KB Output is correct
6 Correct 12 ms 66396 KB Output is correct
7 Correct 10 ms 66476 KB Output is correct
8 Correct 12 ms 66508 KB Output is correct
9 Correct 12 ms 66652 KB Output is correct
10 Correct 14 ms 66392 KB Output is correct
11 Correct 13 ms 66648 KB Output is correct
12 Correct 14 ms 66652 KB Output is correct
13 Correct 12 ms 66396 KB Output is correct
14 Correct 13 ms 66396 KB Output is correct
15 Correct 14 ms 66584 KB Output is correct
16 Correct 12 ms 66648 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 66652 KB Output is correct
20 Correct 11 ms 66904 KB Output is correct
21 Correct 11 ms 66652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 451 ms 120008 KB Output is correct
2 Correct 102 ms 68132 KB Output is correct
3 Correct 94 ms 68176 KB Output is correct
4 Correct 94 ms 68328 KB Output is correct
5 Correct 99 ms 68412 KB Output is correct
6 Correct 84 ms 68192 KB Output is correct
7 Correct 89 ms 68388 KB Output is correct
8 Correct 11 ms 66648 KB Output is correct
9 Correct 12 ms 66652 KB Output is correct
10 Correct 12 ms 66392 KB Output is correct
11 Correct 461 ms 121344 KB Output is correct
12 Correct 480 ms 122620 KB Output is correct
13 Correct 447 ms 121328 KB Output is correct
14 Correct 418 ms 121116 KB Output is correct
15 Correct 489 ms 122480 KB Output is correct
16 Correct 463 ms 123200 KB Output is correct
17 Correct 567 ms 123256 KB Output is correct
18 Correct 480 ms 123216 KB Output is correct
19 Correct 427 ms 122420 KB Output is correct
20 Correct 463 ms 122664 KB Output is correct
21 Correct 449 ms 122660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1087 ms 120944 KB Output is correct
2 Correct 177 ms 68320 KB Output is correct
3 Correct 177 ms 68360 KB Output is correct
4 Correct 174 ms 68392 KB Output is correct
5 Correct 178 ms 68272 KB Output is correct
6 Correct 170 ms 66612 KB Output is correct
7 Correct 174 ms 66576 KB Output is correct
8 Correct 12 ms 66396 KB Output is correct
9 Correct 11 ms 66396 KB Output is correct
10 Correct 11 ms 66396 KB Output is correct
11 Correct 1091 ms 122228 KB Output is correct
12 Correct 1061 ms 125372 KB Output is correct
13 Correct 1080 ms 122052 KB Output is correct
14 Correct 1111 ms 122440 KB Output is correct
15 Correct 1035 ms 125412 KB Output is correct
16 Correct 1084 ms 125556 KB Output is correct
17 Correct 1067 ms 125416 KB Output is correct
18 Correct 1080 ms 125564 KB Output is correct
19 Correct 998 ms 125572 KB Output is correct
20 Correct 1097 ms 125272 KB Output is correct
21 Correct 1022 ms 125384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 451 ms 120008 KB Output is correct
2 Correct 102 ms 68132 KB Output is correct
3 Correct 94 ms 68176 KB Output is correct
4 Correct 94 ms 68328 KB Output is correct
5 Correct 99 ms 68412 KB Output is correct
6 Correct 84 ms 68192 KB Output is correct
7 Correct 89 ms 68388 KB Output is correct
8 Correct 11 ms 66648 KB Output is correct
9 Correct 12 ms 66652 KB Output is correct
10 Correct 12 ms 66392 KB Output is correct
11 Correct 461 ms 121344 KB Output is correct
12 Correct 480 ms 122620 KB Output is correct
13 Correct 447 ms 121328 KB Output is correct
14 Correct 418 ms 121116 KB Output is correct
15 Correct 489 ms 122480 KB Output is correct
16 Correct 463 ms 123200 KB Output is correct
17 Correct 567 ms 123256 KB Output is correct
18 Correct 480 ms 123216 KB Output is correct
19 Correct 427 ms 122420 KB Output is correct
20 Correct 463 ms 122664 KB Output is correct
21 Correct 449 ms 122660 KB Output is correct
22 Correct 1318 ms 124884 KB Output is correct
23 Correct 180 ms 69504 KB Output is correct
24 Correct 161 ms 69440 KB Output is correct
25 Correct 171 ms 69664 KB Output is correct
26 Correct 174 ms 69536 KB Output is correct
27 Correct 193 ms 69628 KB Output is correct
28 Correct 175 ms 69708 KB Output is correct
29 Correct 11 ms 66392 KB Output is correct
30 Correct 11 ms 66396 KB Output is correct
31 Correct 11 ms 66396 KB Output is correct
32 Correct 1240 ms 121968 KB Output is correct
33 Correct 1190 ms 124924 KB Output is correct
34 Correct 1223 ms 121940 KB Output is correct
35 Correct 1227 ms 122188 KB Output is correct
36 Correct 924 ms 122236 KB Output is correct
37 Correct 904 ms 122016 KB Output is correct
38 Correct 914 ms 121936 KB Output is correct
39 Correct 1211 ms 124768 KB Output is correct
40 Correct 1151 ms 125128 KB Output is correct
41 Correct 1293 ms 124900 KB Output is correct
42 Correct 1206 ms 125132 KB Output is correct
43 Correct 1196 ms 124852 KB Output is correct
44 Correct 1138 ms 124896 KB Output is correct
45 Correct 1155 ms 124900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 300 ms 120440 KB Output is correct
2 Correct 72 ms 68508 KB Output is correct
3 Correct 77 ms 68420 KB Output is correct
4 Correct 81 ms 68456 KB Output is correct
5 Correct 89 ms 68432 KB Output is correct
6 Correct 78 ms 68664 KB Output is correct
7 Correct 101 ms 68496 KB Output is correct
8 Correct 13 ms 66476 KB Output is correct
9 Correct 13 ms 66336 KB Output is correct
10 Correct 11 ms 66648 KB Output is correct
11 Correct 284 ms 124224 KB Output is correct
12 Correct 291 ms 124124 KB Output is correct
13 Correct 287 ms 124324 KB Output is correct
14 Correct 295 ms 124588 KB Output is correct
15 Correct 297 ms 124420 KB Output is correct
16 Correct 290 ms 124068 KB Output is correct
17 Correct 288 ms 124128 KB Output is correct
18 Correct 303 ms 124168 KB Output is correct
19 Correct 13 ms 66664 KB Output is correct
20 Correct 13 ms 66392 KB Output is correct
21 Correct 12 ms 66248 KB Output is correct
22 Correct 12 ms 66396 KB Output is correct
23 Correct 12 ms 66248 KB Output is correct
24 Correct 12 ms 66396 KB Output is correct
25 Correct 10 ms 66476 KB Output is correct
26 Correct 12 ms 66508 KB Output is correct
27 Correct 12 ms 66652 KB Output is correct
28 Correct 14 ms 66392 KB Output is correct
29 Correct 13 ms 66648 KB Output is correct
30 Correct 14 ms 66652 KB Output is correct
31 Correct 12 ms 66396 KB Output is correct
32 Correct 13 ms 66396 KB Output is correct
33 Correct 14 ms 66584 KB Output is correct
34 Correct 12 ms 66648 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 66652 KB Output is correct
38 Correct 11 ms 66904 KB Output is correct
39 Correct 11 ms 66652 KB Output is correct
40 Correct 451 ms 120008 KB Output is correct
41 Correct 102 ms 68132 KB Output is correct
42 Correct 94 ms 68176 KB Output is correct
43 Correct 94 ms 68328 KB Output is correct
44 Correct 99 ms 68412 KB Output is correct
45 Correct 84 ms 68192 KB Output is correct
46 Correct 89 ms 68388 KB Output is correct
47 Correct 11 ms 66648 KB Output is correct
48 Correct 12 ms 66652 KB Output is correct
49 Correct 12 ms 66392 KB Output is correct
50 Correct 461 ms 121344 KB Output is correct
51 Correct 480 ms 122620 KB Output is correct
52 Correct 447 ms 121328 KB Output is correct
53 Correct 418 ms 121116 KB Output is correct
54 Correct 489 ms 122480 KB Output is correct
55 Correct 463 ms 123200 KB Output is correct
56 Correct 567 ms 123256 KB Output is correct
57 Correct 480 ms 123216 KB Output is correct
58 Correct 427 ms 122420 KB Output is correct
59 Correct 463 ms 122664 KB Output is correct
60 Correct 449 ms 122660 KB Output is correct
61 Correct 1087 ms 120944 KB Output is correct
62 Correct 177 ms 68320 KB Output is correct
63 Correct 177 ms 68360 KB Output is correct
64 Correct 174 ms 68392 KB Output is correct
65 Correct 178 ms 68272 KB Output is correct
66 Correct 170 ms 66612 KB Output is correct
67 Correct 174 ms 66576 KB Output is correct
68 Correct 12 ms 66396 KB Output is correct
69 Correct 11 ms 66396 KB Output is correct
70 Correct 11 ms 66396 KB Output is correct
71 Correct 1091 ms 122228 KB Output is correct
72 Correct 1061 ms 125372 KB Output is correct
73 Correct 1080 ms 122052 KB Output is correct
74 Correct 1111 ms 122440 KB Output is correct
75 Correct 1035 ms 125412 KB Output is correct
76 Correct 1084 ms 125556 KB Output is correct
77 Correct 1067 ms 125416 KB Output is correct
78 Correct 1080 ms 125564 KB Output is correct
79 Correct 998 ms 125572 KB Output is correct
80 Correct 1097 ms 125272 KB Output is correct
81 Correct 1022 ms 125384 KB Output is correct
82 Correct 1318 ms 124884 KB Output is correct
83 Correct 180 ms 69504 KB Output is correct
84 Correct 161 ms 69440 KB Output is correct
85 Correct 171 ms 69664 KB Output is correct
86 Correct 174 ms 69536 KB Output is correct
87 Correct 193 ms 69628 KB Output is correct
88 Correct 175 ms 69708 KB Output is correct
89 Correct 11 ms 66392 KB Output is correct
90 Correct 11 ms 66396 KB Output is correct
91 Correct 11 ms 66396 KB Output is correct
92 Correct 1240 ms 121968 KB Output is correct
93 Correct 1190 ms 124924 KB Output is correct
94 Correct 1223 ms 121940 KB Output is correct
95 Correct 1227 ms 122188 KB Output is correct
96 Correct 924 ms 122236 KB Output is correct
97 Correct 904 ms 122016 KB Output is correct
98 Correct 914 ms 121936 KB Output is correct
99 Correct 1211 ms 124768 KB Output is correct
100 Correct 1151 ms 125128 KB Output is correct
101 Correct 1293 ms 124900 KB Output is correct
102 Correct 1206 ms 125132 KB Output is correct
103 Correct 1196 ms 124852 KB Output is correct
104 Correct 1138 ms 124896 KB Output is correct
105 Correct 1155 ms 124900 KB Output is correct
106 Correct 1428 ms 125760 KB Output is correct
107 Correct 197 ms 69808 KB Output is correct
108 Correct 196 ms 69716 KB Output is correct
109 Correct 206 ms 69820 KB Output is correct
110 Correct 11 ms 66336 KB Output is correct
111 Correct 11 ms 66392 KB Output is correct
112 Correct 10 ms 66392 KB Output is correct
113 Correct 1178 ms 125136 KB Output is correct
114 Correct 1206 ms 124864 KB Output is correct
115 Correct 1217 ms 125080 KB Output is correct
116 Correct 1171 ms 124924 KB Output is correct
117 Correct 1443 ms 126268 KB Output is correct
118 Correct 1172 ms 124768 KB Output is correct
119 Correct 1154 ms 124784 KB Output is correct
120 Correct 409 ms 123740 KB Output is correct
121 Correct 486 ms 123476 KB Output is correct
122 Correct 398 ms 123372 KB Output is correct
123 Correct 397 ms 122576 KB Output is correct
124 Correct 366 ms 122584 KB Output is correct
125 Correct 364 ms 122648 KB Output is correct
126 Correct 1470 ms 122696 KB Output is correct
127 Correct 1435 ms 122440 KB Output is correct
128 Correct 1466 ms 125808 KB Output is correct
129 Correct 1453 ms 122900 KB Output is correct
130 Correct 994 ms 122520 KB Output is correct
131 Correct 950 ms 122808 KB Output is correct
132 Correct 928 ms 122728 KB Output is correct
133 Correct 1453 ms 126064 KB Output is correct
134 Correct 1401 ms 125740 KB Output is correct
135 Correct 1420 ms 125992 KB Output is correct
136 Correct 196 ms 69832 KB Output is correct
137 Correct 216 ms 69828 KB Output is correct
138 Correct 195 ms 69784 KB Output is correct