#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p2;
const int N=3e5+5;
const int K=1<<20;
int n,q;
ll a[N],b[N];
struct segtree{
struct node{
ll sz,ans,all,sum;
p2 pre,suf;
node(ll x=0):sz(1),pre(p2(1,x)),suf(p2(1,x)),all(1),ans(1),sum(x){}
friend node operator+(node a,node b){
node c;
bool ok=(a.suf.second==b.pre.second);
bool oka=(a.suf.first==a.sz);
bool okb=(b.pre.first==b.sz);
c.sz=a.sz+b.sz;
c.sum=a.sum+b.sum;
if(ok&&oka){
c.pre=b.pre;
c.pre.first+=a.sz;
}else{
c.pre=a.pre;
}
if(ok&&okb){
c.suf=a.suf;
c.suf.first+=b.sz;
}else{
c.suf=b.suf;
}
if(ok&&oka&&okb){
c.all=a.sz+b.sz;
}else{
c.all=0;
}
c.ans=max(a.ans,b.ans);
if(ok){
c.ans=max(c.ans,a.suf.first+b.pre.first);
}
return c;
}
}t[K];
ll lz[K];
bool islz[K];
void pushlz(int l,int r,int i){
if(islz[i]){
t[i].all=t[i].ans=t[i].sz;
t[i].sum=t[i].sz*lz[i];
t[i].pre=t[i].suf=p2(t[i].sz,lz[i]);
if(l<r){
lz[i*2]=lz[i*2+1]=lz[i];
islz[i*2]=islz[i*2+1]=true;
}
}else{
t[i].sum+=t[i].sz*lz[i];
t[i].pre.second+=lz[i];
t[i].suf.second+=lz[i];
if(l<r){
lz[i*2]+=lz[i];
lz[i*2+1]+=lz[i];
}
}
lz[i]=0;
islz[i]=false;
}
void build(int l,int r,int i){
if(l==r)return void(t[i]=b[l]);
int m=(l+r)/2;
build(l,m,i*2);
build(m+1,r,i*2+1);
t[i]=t[i*2]+t[i*2+1];
}
void build(){
build(1,n+1,1);
}
void update(int l,int r,int i,int x,int y,ll v){
pushlz(l,r,i);
if(y<l||r<x)return;
if(x<=l&&r<=y)return lz[i]=v,pushlz(l,r,i),void();
int m=(l+r)/2;
update(l,m,i*2,x,y,v);
update(m+1,r,i*2+1,x,y,v);
t[i]=t[i*2]+t[i*2+1];
}
void update(int x,int y,ll v){
update(1,n+1,1,x,y,v);
}
void update2(int l,int r,int i,int x,int y,ll v){
pushlz(l,r,i);
if(y<l||r<x)return;
if(x<=l&&r<=y)return islz[i]=true,lz[i]=v,pushlz(l,r,i),void();
int m=(l+r)/2;
update2(l,m,i*2,x,y,v);
update2(m+1,r,i*2+1,x,y,v);
t[i]=t[i*2]+t[i*2+1];
}
void update2(int x,int y,ll v){
update2(1,n+1,1,x,y,v);
}
node query(int l,int r,int i,int x,int y){
pushlz(l,r,i);
if(x<=l&&r<=y)return t[i];
int m=(l+r)/2;
if(x<=m&&m<y)return query(l,m,i*2,x,y)+query(m+1,r,i*2+1,x,y);
if(x<=m)return query(l,m,i*2,x,y);
else return query(m+1,r,i*2+1,x,y);
}
node query(int x,int y){
return query(1,n+1,1,x,y);
}
}s;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> q;
for(int i=1;i<=n;i++)cin >> a[i];
for(int i=1;i<=n;i++)b[i]=a[i]-a[i-1];
s.build();
while(q--){
int t;
cin >> t;
if(t==1){
ll l,r,a,b;
cin >> l >> r >> a >> b;
s.update(l,l,a);
s.update(l+1,r,b);
s.update(r+1,r+1,-a-(r-l)*b);
}else if(t==2){
ll l,r,a,b;
cin >> l >> r >> a >> b;
ll le=(l==1?0:s.query(1,l-1).sum);
ll ri=s.query(1,r+1).sum;
s.update2(l,l,a-le);
s.update2(r+1,r+1,ri-a-(r-l)*b);
s.update2(l+1,r,b);
}else{
ll l,r;
cin >> l >> r;
cout << (l==r?0:s.query(l+1,r).ans)+1 << "\n";
}
}
}
Compilation message
Progression.cpp: In constructor 'segtree::node::node(ll)':
Progression.cpp:17:16: warning: 'segtree::node::suf' will be initialized after [-Wreorder]
17 | p2 pre,suf;
| ^~~
Progression.cpp:16:19: warning: 'll segtree::node::all' [-Wreorder]
16 | ll sz,ans,all,sum;
| ^~~
Progression.cpp:18:9: warning: when initialized here [-Wreorder]
18 | node(ll x=0):sz(1),pre(p2(1,x)),suf(p2(1,x)),all(1),ans(1),sum(x){}
| ^~~~
Progression.cpp:16:19: warning: 'segtree::node::all' will be initialized after [-Wreorder]
16 | ll sz,ans,all,sum;
| ^~~
Progression.cpp:16:15: warning: 'll segtree::node::ans' [-Wreorder]
16 | ll sz,ans,all,sum;
| ^~~
Progression.cpp:18:9: warning: when initialized here [-Wreorder]
18 | node(ll x=0):sz(1),pre(p2(1,x)),suf(p2(1,x)),all(1),ans(1),sum(x){}
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
540 ms |
75004 KB |
Output is correct |
2 |
Correct |
166 ms |
69168 KB |
Output is correct |
3 |
Correct |
160 ms |
69208 KB |
Output is correct |
4 |
Correct |
160 ms |
69212 KB |
Output is correct |
5 |
Correct |
166 ms |
69224 KB |
Output is correct |
6 |
Correct |
165 ms |
69196 KB |
Output is correct |
7 |
Correct |
163 ms |
69128 KB |
Output is correct |
8 |
Correct |
26 ms |
66000 KB |
Output is correct |
9 |
Correct |
25 ms |
66000 KB |
Output is correct |
10 |
Correct |
28 ms |
65936 KB |
Output is correct |
11 |
Correct |
559 ms |
74896 KB |
Output is correct |
12 |
Correct |
540 ms |
74864 KB |
Output is correct |
13 |
Correct |
541 ms |
75212 KB |
Output is correct |
14 |
Correct |
560 ms |
75112 KB |
Output is correct |
15 |
Correct |
554 ms |
75216 KB |
Output is correct |
16 |
Correct |
557 ms |
74900 KB |
Output is correct |
17 |
Correct |
539 ms |
74808 KB |
Output is correct |
18 |
Correct |
557 ms |
74900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
66008 KB |
Output is correct |
2 |
Correct |
31 ms |
65936 KB |
Output is correct |
3 |
Correct |
29 ms |
65976 KB |
Output is correct |
4 |
Correct |
29 ms |
65960 KB |
Output is correct |
5 |
Correct |
28 ms |
65984 KB |
Output is correct |
6 |
Correct |
29 ms |
65992 KB |
Output is correct |
7 |
Correct |
25 ms |
66000 KB |
Output is correct |
8 |
Correct |
26 ms |
65964 KB |
Output is correct |
9 |
Correct |
26 ms |
65984 KB |
Output is correct |
10 |
Correct |
25 ms |
66032 KB |
Output is correct |
11 |
Correct |
27 ms |
65952 KB |
Output is correct |
12 |
Correct |
27 ms |
66052 KB |
Output is correct |
13 |
Correct |
29 ms |
65984 KB |
Output is correct |
14 |
Correct |
26 ms |
66004 KB |
Output is correct |
15 |
Correct |
26 ms |
66000 KB |
Output is correct |
16 |
Correct |
26 ms |
65980 KB |
Output is correct |
17 |
Correct |
31 ms |
66028 KB |
Output is correct |
18 |
Correct |
27 ms |
66012 KB |
Output is correct |
19 |
Correct |
27 ms |
66004 KB |
Output is correct |
20 |
Correct |
26 ms |
65988 KB |
Output is correct |
21 |
Correct |
27 ms |
65996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
284 ms |
84640 KB |
Output is correct |
2 |
Correct |
105 ms |
68684 KB |
Output is correct |
3 |
Correct |
91 ms |
68684 KB |
Output is correct |
4 |
Correct |
92 ms |
68680 KB |
Output is correct |
5 |
Correct |
113 ms |
68912 KB |
Output is correct |
6 |
Correct |
100 ms |
68788 KB |
Output is correct |
7 |
Correct |
99 ms |
68816 KB |
Output is correct |
8 |
Correct |
26 ms |
65996 KB |
Output is correct |
9 |
Correct |
26 ms |
65992 KB |
Output is correct |
10 |
Correct |
26 ms |
65928 KB |
Output is correct |
11 |
Correct |
298 ms |
84412 KB |
Output is correct |
12 |
Correct |
287 ms |
84776 KB |
Output is correct |
13 |
Correct |
318 ms |
84532 KB |
Output is correct |
14 |
Correct |
303 ms |
84304 KB |
Output is correct |
15 |
Correct |
293 ms |
84564 KB |
Output is correct |
16 |
Correct |
303 ms |
84852 KB |
Output is correct |
17 |
Correct |
322 ms |
84980 KB |
Output is correct |
18 |
Correct |
325 ms |
85000 KB |
Output is correct |
19 |
Correct |
274 ms |
84156 KB |
Output is correct |
20 |
Correct |
283 ms |
84076 KB |
Output is correct |
21 |
Correct |
276 ms |
84252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
611 ms |
83712 KB |
Output is correct |
2 |
Correct |
181 ms |
69324 KB |
Output is correct |
3 |
Correct |
163 ms |
69228 KB |
Output is correct |
4 |
Correct |
155 ms |
69276 KB |
Output is correct |
5 |
Correct |
160 ms |
69324 KB |
Output is correct |
6 |
Correct |
172 ms |
69336 KB |
Output is correct |
7 |
Correct |
157 ms |
69312 KB |
Output is correct |
8 |
Correct |
29 ms |
65984 KB |
Output is correct |
9 |
Correct |
37 ms |
65932 KB |
Output is correct |
10 |
Correct |
29 ms |
65948 KB |
Output is correct |
11 |
Correct |
628 ms |
85148 KB |
Output is correct |
12 |
Correct |
607 ms |
85076 KB |
Output is correct |
13 |
Correct |
589 ms |
84980 KB |
Output is correct |
14 |
Correct |
585 ms |
84824 KB |
Output is correct |
15 |
Correct |
641 ms |
84920 KB |
Output is correct |
16 |
Correct |
619 ms |
84788 KB |
Output is correct |
17 |
Correct |
620 ms |
84812 KB |
Output is correct |
18 |
Correct |
607 ms |
84680 KB |
Output is correct |
19 |
Correct |
609 ms |
84476 KB |
Output is correct |
20 |
Correct |
631 ms |
84536 KB |
Output is correct |
21 |
Correct |
624 ms |
84240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
284 ms |
84640 KB |
Output is correct |
2 |
Correct |
105 ms |
68684 KB |
Output is correct |
3 |
Correct |
91 ms |
68684 KB |
Output is correct |
4 |
Correct |
92 ms |
68680 KB |
Output is correct |
5 |
Correct |
113 ms |
68912 KB |
Output is correct |
6 |
Correct |
100 ms |
68788 KB |
Output is correct |
7 |
Correct |
99 ms |
68816 KB |
Output is correct |
8 |
Correct |
26 ms |
65996 KB |
Output is correct |
9 |
Correct |
26 ms |
65992 KB |
Output is correct |
10 |
Correct |
26 ms |
65928 KB |
Output is correct |
11 |
Correct |
298 ms |
84412 KB |
Output is correct |
12 |
Correct |
287 ms |
84776 KB |
Output is correct |
13 |
Correct |
318 ms |
84532 KB |
Output is correct |
14 |
Correct |
303 ms |
84304 KB |
Output is correct |
15 |
Correct |
293 ms |
84564 KB |
Output is correct |
16 |
Correct |
303 ms |
84852 KB |
Output is correct |
17 |
Correct |
322 ms |
84980 KB |
Output is correct |
18 |
Correct |
325 ms |
85000 KB |
Output is correct |
19 |
Correct |
274 ms |
84156 KB |
Output is correct |
20 |
Correct |
283 ms |
84076 KB |
Output is correct |
21 |
Correct |
276 ms |
84252 KB |
Output is correct |
22 |
Correct |
628 ms |
83968 KB |
Output is correct |
23 |
Correct |
145 ms |
69240 KB |
Output is correct |
24 |
Correct |
140 ms |
69172 KB |
Output is correct |
25 |
Correct |
137 ms |
69224 KB |
Output is correct |
26 |
Correct |
149 ms |
69236 KB |
Output is correct |
27 |
Correct |
148 ms |
69256 KB |
Output is correct |
28 |
Correct |
145 ms |
69220 KB |
Output is correct |
29 |
Correct |
33 ms |
65956 KB |
Output is correct |
30 |
Correct |
31 ms |
65984 KB |
Output is correct |
31 |
Correct |
29 ms |
65984 KB |
Output is correct |
32 |
Correct |
608 ms |
84044 KB |
Output is correct |
33 |
Correct |
614 ms |
83836 KB |
Output is correct |
34 |
Correct |
665 ms |
83904 KB |
Output is correct |
35 |
Correct |
644 ms |
83880 KB |
Output is correct |
36 |
Correct |
521 ms |
84036 KB |
Output is correct |
37 |
Correct |
492 ms |
84012 KB |
Output is correct |
38 |
Correct |
511 ms |
83904 KB |
Output is correct |
39 |
Correct |
604 ms |
83816 KB |
Output is correct |
40 |
Correct |
640 ms |
84192 KB |
Output is correct |
41 |
Correct |
623 ms |
83636 KB |
Output is correct |
42 |
Correct |
650 ms |
84444 KB |
Output is correct |
43 |
Correct |
620 ms |
85092 KB |
Output is correct |
44 |
Correct |
617 ms |
85052 KB |
Output is correct |
45 |
Correct |
605 ms |
85108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
540 ms |
75004 KB |
Output is correct |
2 |
Correct |
166 ms |
69168 KB |
Output is correct |
3 |
Correct |
160 ms |
69208 KB |
Output is correct |
4 |
Correct |
160 ms |
69212 KB |
Output is correct |
5 |
Correct |
166 ms |
69224 KB |
Output is correct |
6 |
Correct |
165 ms |
69196 KB |
Output is correct |
7 |
Correct |
163 ms |
69128 KB |
Output is correct |
8 |
Correct |
26 ms |
66000 KB |
Output is correct |
9 |
Correct |
25 ms |
66000 KB |
Output is correct |
10 |
Correct |
28 ms |
65936 KB |
Output is correct |
11 |
Correct |
559 ms |
74896 KB |
Output is correct |
12 |
Correct |
540 ms |
74864 KB |
Output is correct |
13 |
Correct |
541 ms |
75212 KB |
Output is correct |
14 |
Correct |
560 ms |
75112 KB |
Output is correct |
15 |
Correct |
554 ms |
75216 KB |
Output is correct |
16 |
Correct |
557 ms |
74900 KB |
Output is correct |
17 |
Correct |
539 ms |
74808 KB |
Output is correct |
18 |
Correct |
557 ms |
74900 KB |
Output is correct |
19 |
Correct |
28 ms |
66008 KB |
Output is correct |
20 |
Correct |
31 ms |
65936 KB |
Output is correct |
21 |
Correct |
29 ms |
65976 KB |
Output is correct |
22 |
Correct |
29 ms |
65960 KB |
Output is correct |
23 |
Correct |
28 ms |
65984 KB |
Output is correct |
24 |
Correct |
29 ms |
65992 KB |
Output is correct |
25 |
Correct |
25 ms |
66000 KB |
Output is correct |
26 |
Correct |
26 ms |
65964 KB |
Output is correct |
27 |
Correct |
26 ms |
65984 KB |
Output is correct |
28 |
Correct |
25 ms |
66032 KB |
Output is correct |
29 |
Correct |
27 ms |
65952 KB |
Output is correct |
30 |
Correct |
27 ms |
66052 KB |
Output is correct |
31 |
Correct |
29 ms |
65984 KB |
Output is correct |
32 |
Correct |
26 ms |
66004 KB |
Output is correct |
33 |
Correct |
26 ms |
66000 KB |
Output is correct |
34 |
Correct |
26 ms |
65980 KB |
Output is correct |
35 |
Correct |
31 ms |
66028 KB |
Output is correct |
36 |
Correct |
27 ms |
66012 KB |
Output is correct |
37 |
Correct |
27 ms |
66004 KB |
Output is correct |
38 |
Correct |
26 ms |
65988 KB |
Output is correct |
39 |
Correct |
27 ms |
65996 KB |
Output is correct |
40 |
Correct |
284 ms |
84640 KB |
Output is correct |
41 |
Correct |
105 ms |
68684 KB |
Output is correct |
42 |
Correct |
91 ms |
68684 KB |
Output is correct |
43 |
Correct |
92 ms |
68680 KB |
Output is correct |
44 |
Correct |
113 ms |
68912 KB |
Output is correct |
45 |
Correct |
100 ms |
68788 KB |
Output is correct |
46 |
Correct |
99 ms |
68816 KB |
Output is correct |
47 |
Correct |
26 ms |
65996 KB |
Output is correct |
48 |
Correct |
26 ms |
65992 KB |
Output is correct |
49 |
Correct |
26 ms |
65928 KB |
Output is correct |
50 |
Correct |
298 ms |
84412 KB |
Output is correct |
51 |
Correct |
287 ms |
84776 KB |
Output is correct |
52 |
Correct |
318 ms |
84532 KB |
Output is correct |
53 |
Correct |
303 ms |
84304 KB |
Output is correct |
54 |
Correct |
293 ms |
84564 KB |
Output is correct |
55 |
Correct |
303 ms |
84852 KB |
Output is correct |
56 |
Correct |
322 ms |
84980 KB |
Output is correct |
57 |
Correct |
325 ms |
85000 KB |
Output is correct |
58 |
Correct |
274 ms |
84156 KB |
Output is correct |
59 |
Correct |
283 ms |
84076 KB |
Output is correct |
60 |
Correct |
276 ms |
84252 KB |
Output is correct |
61 |
Correct |
611 ms |
83712 KB |
Output is correct |
62 |
Correct |
181 ms |
69324 KB |
Output is correct |
63 |
Correct |
163 ms |
69228 KB |
Output is correct |
64 |
Correct |
155 ms |
69276 KB |
Output is correct |
65 |
Correct |
160 ms |
69324 KB |
Output is correct |
66 |
Correct |
172 ms |
69336 KB |
Output is correct |
67 |
Correct |
157 ms |
69312 KB |
Output is correct |
68 |
Correct |
29 ms |
65984 KB |
Output is correct |
69 |
Correct |
37 ms |
65932 KB |
Output is correct |
70 |
Correct |
29 ms |
65948 KB |
Output is correct |
71 |
Correct |
628 ms |
85148 KB |
Output is correct |
72 |
Correct |
607 ms |
85076 KB |
Output is correct |
73 |
Correct |
589 ms |
84980 KB |
Output is correct |
74 |
Correct |
585 ms |
84824 KB |
Output is correct |
75 |
Correct |
641 ms |
84920 KB |
Output is correct |
76 |
Correct |
619 ms |
84788 KB |
Output is correct |
77 |
Correct |
620 ms |
84812 KB |
Output is correct |
78 |
Correct |
607 ms |
84680 KB |
Output is correct |
79 |
Correct |
609 ms |
84476 KB |
Output is correct |
80 |
Correct |
631 ms |
84536 KB |
Output is correct |
81 |
Correct |
624 ms |
84240 KB |
Output is correct |
82 |
Correct |
628 ms |
83968 KB |
Output is correct |
83 |
Correct |
145 ms |
69240 KB |
Output is correct |
84 |
Correct |
140 ms |
69172 KB |
Output is correct |
85 |
Correct |
137 ms |
69224 KB |
Output is correct |
86 |
Correct |
149 ms |
69236 KB |
Output is correct |
87 |
Correct |
148 ms |
69256 KB |
Output is correct |
88 |
Correct |
145 ms |
69220 KB |
Output is correct |
89 |
Correct |
33 ms |
65956 KB |
Output is correct |
90 |
Correct |
31 ms |
65984 KB |
Output is correct |
91 |
Correct |
29 ms |
65984 KB |
Output is correct |
92 |
Correct |
608 ms |
84044 KB |
Output is correct |
93 |
Correct |
614 ms |
83836 KB |
Output is correct |
94 |
Correct |
665 ms |
83904 KB |
Output is correct |
95 |
Correct |
644 ms |
83880 KB |
Output is correct |
96 |
Correct |
521 ms |
84036 KB |
Output is correct |
97 |
Correct |
492 ms |
84012 KB |
Output is correct |
98 |
Correct |
511 ms |
83904 KB |
Output is correct |
99 |
Correct |
604 ms |
83816 KB |
Output is correct |
100 |
Correct |
640 ms |
84192 KB |
Output is correct |
101 |
Correct |
623 ms |
83636 KB |
Output is correct |
102 |
Correct |
650 ms |
84444 KB |
Output is correct |
103 |
Correct |
620 ms |
85092 KB |
Output is correct |
104 |
Correct |
617 ms |
85052 KB |
Output is correct |
105 |
Correct |
605 ms |
85108 KB |
Output is correct |
106 |
Correct |
795 ms |
83120 KB |
Output is correct |
107 |
Correct |
190 ms |
68812 KB |
Output is correct |
108 |
Correct |
190 ms |
68808 KB |
Output is correct |
109 |
Correct |
190 ms |
68852 KB |
Output is correct |
110 |
Correct |
30 ms |
65888 KB |
Output is correct |
111 |
Correct |
29 ms |
65988 KB |
Output is correct |
112 |
Correct |
29 ms |
65988 KB |
Output is correct |
113 |
Correct |
658 ms |
83100 KB |
Output is correct |
114 |
Correct |
616 ms |
83144 KB |
Output is correct |
115 |
Correct |
640 ms |
83036 KB |
Output is correct |
116 |
Correct |
589 ms |
82764 KB |
Output is correct |
117 |
Correct |
801 ms |
83004 KB |
Output is correct |
118 |
Correct |
597 ms |
82616 KB |
Output is correct |
119 |
Correct |
585 ms |
82800 KB |
Output is correct |
120 |
Correct |
320 ms |
83688 KB |
Output is correct |
121 |
Correct |
314 ms |
83788 KB |
Output is correct |
122 |
Correct |
303 ms |
83788 KB |
Output is correct |
123 |
Correct |
269 ms |
82860 KB |
Output is correct |
124 |
Correct |
264 ms |
82880 KB |
Output is correct |
125 |
Correct |
291 ms |
82784 KB |
Output is correct |
126 |
Correct |
758 ms |
82776 KB |
Output is correct |
127 |
Correct |
794 ms |
82548 KB |
Output is correct |
128 |
Correct |
787 ms |
82624 KB |
Output is correct |
129 |
Correct |
770 ms |
82460 KB |
Output is correct |
130 |
Correct |
584 ms |
83328 KB |
Output is correct |
131 |
Correct |
551 ms |
83236 KB |
Output is correct |
132 |
Correct |
525 ms |
83312 KB |
Output is correct |
133 |
Correct |
801 ms |
82540 KB |
Output is correct |
134 |
Correct |
798 ms |
82528 KB |
Output is correct |
135 |
Correct |
787 ms |
82584 KB |
Output is correct |
136 |
Correct |
190 ms |
68248 KB |
Output is correct |
137 |
Correct |
191 ms |
68164 KB |
Output is correct |
138 |
Correct |
189 ms |
68172 KB |
Output is correct |