#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define endl '\n'
#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--))
#define sz(x) (int) (x).size()
#define all(x) (x).begin(),(x).end()
const ll INF=1e18;
int arr[300010];
struct dat{
ll ans;
ll lval,llen;
ll rval,rlen;
ll l,r;
dat(){
llen=-1,rlen=-1;
}
dat(ll i,ll j,ll _l,ll _r){
ans=j;
lval=i;
llen=j;
rval=-1;
rlen=-1;
l=_l;
r=_r;
}
};
dat merge(dat i,dat j){
dat res=dat();
res.l=i.l,res.r=j.r;
res.ans=max(i.ans,j.ans);
ll temp=j.l-i.r;
if (i.llen==-1){
res.llen=1;
res.lval=temp;
}
else if (i.rlen==-1){
if (i.lval==temp){
res.llen=i.llen+1;
res.lval=temp;
}
else{
res.llen=i.llen;
res.lval=i.lval;
res.rlen=1;
res.rval=temp;
}
}
else{
if (i.rval==temp){
res.llen=i.llen;
res.lval=i.lval;
res.rlen=i.rlen+1;
res.rval=temp;
}
else{
res.llen=i.llen;
res.lval=i.lval;
res.rlen=1;
res.rval=temp;
}
}
res.ans=max(res.ans,max(res.llen,res.rlen));
if (j.llen!=-1){
if (res.rlen==-1){
if (res.lval==j.lval) res.llen+=j.llen;
else{
res.rlen=j.llen;
res.rval=j.lval;
}
}
else{
if (res.rval==j.lval) res.rlen+=j.llen;
else{
res.rlen=j.llen;
res.rval=j.lval;
}
}
}
res.ans=max(res.ans,max(res.llen,res.rlen));
if (j.rlen!=-1){
res.rlen=j.rlen;
res.rval=j.rval;
}
res.ans=max(res.ans,max(res.llen,res.rlen));
return res;
}
struct node{
ll s,e,m,len;
dat val;
ll incs=0,incc=0;
ll sets=INF,setc=INF;
node *l,*r;
node (ll _s,ll _e){
s=_s,e=_e,m=s+e>>1;
len=e-s+1;
if (s!=e){
l=new node(s,m);
r=new node(m+1,e);
val=merge(l->val,r->val);
}
else{
val=dat(-1,-1,arr[s],arr[s]);
}
}
void propo(){
if (sets!=INF){
if (s==e) val=dat(-1,-1,sets,sets);
else val=dat(setc,len-1,sets,sets+(len-1)*setc);
if (s!=e){
l->incs=l->incc=0;
l->sets=sets,l->setc=setc;
r->incs=r->incc=0;
r->sets=sets+setc*l->len,r->setc=setc;
}
sets=INF;
setc=INF;
}
if (incs || incc){
val.l+=incs,val.r+=incs+(len-1)*incc;
val.lval+=incc,val.rval+=incc;
if (s!=e){
l->incs+=incs,l->incc+=incc;
r->incs+=incs+incc*l->len,r->incc+=incc;
}
incs=0;
incc=0;
}
}
void patch(ll i,ll j,ll S,ll C){
propo();
if (s==i && e==j) incs=S,incc=C;
else{
if (j<=m) l->patch(i,j,S,C);
else if (m<i) r->patch(i,j,S,C);
else l->patch(i,m,S,C),r->patch(m+1,j,S+(m-i+1)*C,C);
l->propo(),r->propo();
val=merge(l->val,r->val);
}
}
void rewrite(ll i,ll j,ll S,ll C){
propo();
if (s==i && e==j) sets=S,setc=C;
else{
if (j<=m) l->rewrite(i,j,S,C);
else if (m<i) r->rewrite(i,j,S,C);
else l->rewrite(i,m,S,C),r->rewrite(m+1,j,S+(m-i+1)*C,C);
l->propo(),r->propo();
val=merge(l->val,r->val);
}
}
dat query(ll i,ll j){
propo();
if (s==i && e==j) return val;
else if (j<=m) return l->query(i,j);
else if (m<i) return r->query(i,j);
else return merge(l->query(i,m),r->query(m+1,j));
}
void print(){
cout<<s<<" "<<e<<endl;
cout<<val.llen<<" "<<val.lval<<" "<<val.rlen<<" "<<val.rval<<" "<<val.ans<<endl;
if (s!=e){
l->print();
r->print();
}
}
} *root;
ll n,q;
int main(){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin>>n>>q;
rep(x,1,n+1) cin>>arr[x];
root=new node(0,300005);
ll a,b,c,d;
while (q--){
cin>>a;
if (a==1){
cin>>a>>b>>c>>d;
root->patch(a,b,c,d);
}
else if (a==2){
cin>>a>>b>>c>>d;
root->rewrite(a,b,c,d);
}
else{
cin>>a>>b;
if (a==b) cout<<1<<endl;
else cout<<root->query(a,b).ans+1<<endl;
//root->print();
}
}
//rep(x,1,n+1) cout<<root->query(x,x).l<<" ";
}
Compilation message
Progression.cpp: In constructor 'node::node(long long int, long long int)':
Progression.cpp:233:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
233 | s=_s,e=_e,m=s+e>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
682 ms |
94712 KB |
Output is correct |
2 |
Correct |
337 ms |
88056 KB |
Output is correct |
3 |
Correct |
333 ms |
88140 KB |
Output is correct |
4 |
Correct |
343 ms |
88184 KB |
Output is correct |
5 |
Correct |
350 ms |
88184 KB |
Output is correct |
6 |
Correct |
332 ms |
88184 KB |
Output is correct |
7 |
Correct |
344 ms |
88056 KB |
Output is correct |
8 |
Correct |
68 ms |
84856 KB |
Output is correct |
9 |
Correct |
69 ms |
84856 KB |
Output is correct |
10 |
Correct |
67 ms |
84924 KB |
Output is correct |
11 |
Correct |
671 ms |
94704 KB |
Output is correct |
12 |
Correct |
678 ms |
94712 KB |
Output is correct |
13 |
Correct |
668 ms |
95096 KB |
Output is correct |
14 |
Correct |
684 ms |
95400 KB |
Output is correct |
15 |
Correct |
665 ms |
94916 KB |
Output is correct |
16 |
Correct |
693 ms |
94668 KB |
Output is correct |
17 |
Correct |
681 ms |
94548 KB |
Output is correct |
18 |
Correct |
692 ms |
94712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
84860 KB |
Output is correct |
2 |
Correct |
67 ms |
84856 KB |
Output is correct |
3 |
Correct |
68 ms |
84856 KB |
Output is correct |
4 |
Correct |
72 ms |
84856 KB |
Output is correct |
5 |
Correct |
70 ms |
84856 KB |
Output is correct |
6 |
Correct |
70 ms |
84856 KB |
Output is correct |
7 |
Correct |
67 ms |
84856 KB |
Output is correct |
8 |
Correct |
68 ms |
84856 KB |
Output is correct |
9 |
Correct |
71 ms |
84900 KB |
Output is correct |
10 |
Correct |
69 ms |
84936 KB |
Output is correct |
11 |
Correct |
68 ms |
84916 KB |
Output is correct |
12 |
Correct |
69 ms |
84856 KB |
Output is correct |
13 |
Correct |
69 ms |
84856 KB |
Output is correct |
14 |
Correct |
70 ms |
84884 KB |
Output is correct |
15 |
Correct |
72 ms |
84960 KB |
Output is correct |
16 |
Correct |
72 ms |
84856 KB |
Output is correct |
17 |
Correct |
68 ms |
84856 KB |
Output is correct |
18 |
Correct |
69 ms |
84856 KB |
Output is correct |
19 |
Correct |
74 ms |
84856 KB |
Output is correct |
20 |
Correct |
68 ms |
84856 KB |
Output is correct |
21 |
Correct |
67 ms |
84856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
484 ms |
93200 KB |
Output is correct |
2 |
Correct |
187 ms |
87548 KB |
Output is correct |
3 |
Correct |
175 ms |
87544 KB |
Output is correct |
4 |
Correct |
165 ms |
87544 KB |
Output is correct |
5 |
Correct |
189 ms |
87800 KB |
Output is correct |
6 |
Correct |
189 ms |
87800 KB |
Output is correct |
7 |
Correct |
195 ms |
87676 KB |
Output is correct |
8 |
Correct |
72 ms |
84920 KB |
Output is correct |
9 |
Correct |
70 ms |
84856 KB |
Output is correct |
10 |
Correct |
81 ms |
84840 KB |
Output is correct |
11 |
Correct |
544 ms |
91892 KB |
Output is correct |
12 |
Correct |
466 ms |
93176 KB |
Output is correct |
13 |
Correct |
586 ms |
91896 KB |
Output is correct |
14 |
Correct |
563 ms |
91768 KB |
Output is correct |
15 |
Correct |
459 ms |
93080 KB |
Output is correct |
16 |
Correct |
554 ms |
93688 KB |
Output is correct |
17 |
Correct |
578 ms |
93700 KB |
Output is correct |
18 |
Correct |
567 ms |
93956 KB |
Output is correct |
19 |
Correct |
496 ms |
93096 KB |
Output is correct |
20 |
Correct |
470 ms |
93048 KB |
Output is correct |
21 |
Correct |
489 ms |
93164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
909 ms |
95952 KB |
Output is correct |
2 |
Correct |
294 ms |
88356 KB |
Output is correct |
3 |
Correct |
377 ms |
88188 KB |
Output is correct |
4 |
Correct |
350 ms |
88280 KB |
Output is correct |
5 |
Correct |
306 ms |
88280 KB |
Output is correct |
6 |
Correct |
306 ms |
88436 KB |
Output is correct |
7 |
Correct |
348 ms |
88232 KB |
Output is correct |
8 |
Correct |
74 ms |
84840 KB |
Output is correct |
9 |
Correct |
66 ms |
84984 KB |
Output is correct |
10 |
Correct |
66 ms |
84888 KB |
Output is correct |
11 |
Correct |
842 ms |
92868 KB |
Output is correct |
12 |
Correct |
772 ms |
95928 KB |
Output is correct |
13 |
Correct |
855 ms |
92780 KB |
Output is correct |
14 |
Correct |
843 ms |
92676 KB |
Output is correct |
15 |
Correct |
794 ms |
95916 KB |
Output is correct |
16 |
Correct |
844 ms |
96012 KB |
Output is correct |
17 |
Correct |
830 ms |
96000 KB |
Output is correct |
18 |
Correct |
833 ms |
96228 KB |
Output is correct |
19 |
Correct |
785 ms |
95924 KB |
Output is correct |
20 |
Correct |
835 ms |
96048 KB |
Output is correct |
21 |
Correct |
789 ms |
95920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
484 ms |
93200 KB |
Output is correct |
2 |
Correct |
187 ms |
87548 KB |
Output is correct |
3 |
Correct |
175 ms |
87544 KB |
Output is correct |
4 |
Correct |
165 ms |
87544 KB |
Output is correct |
5 |
Correct |
189 ms |
87800 KB |
Output is correct |
6 |
Correct |
189 ms |
87800 KB |
Output is correct |
7 |
Correct |
195 ms |
87676 KB |
Output is correct |
8 |
Correct |
72 ms |
84920 KB |
Output is correct |
9 |
Correct |
70 ms |
84856 KB |
Output is correct |
10 |
Correct |
81 ms |
84840 KB |
Output is correct |
11 |
Correct |
544 ms |
91892 KB |
Output is correct |
12 |
Correct |
466 ms |
93176 KB |
Output is correct |
13 |
Correct |
586 ms |
91896 KB |
Output is correct |
14 |
Correct |
563 ms |
91768 KB |
Output is correct |
15 |
Correct |
459 ms |
93080 KB |
Output is correct |
16 |
Correct |
554 ms |
93688 KB |
Output is correct |
17 |
Correct |
578 ms |
93700 KB |
Output is correct |
18 |
Correct |
567 ms |
93956 KB |
Output is correct |
19 |
Correct |
496 ms |
93096 KB |
Output is correct |
20 |
Correct |
470 ms |
93048 KB |
Output is correct |
21 |
Correct |
489 ms |
93164 KB |
Output is correct |
22 |
Correct |
1365 ms |
95408 KB |
Output is correct |
23 |
Correct |
294 ms |
88188 KB |
Output is correct |
24 |
Correct |
293 ms |
88184 KB |
Output is correct |
25 |
Correct |
281 ms |
88184 KB |
Output is correct |
26 |
Correct |
294 ms |
88180 KB |
Output is correct |
27 |
Correct |
300 ms |
88196 KB |
Output is correct |
28 |
Correct |
321 ms |
88156 KB |
Output is correct |
29 |
Correct |
74 ms |
84856 KB |
Output is correct |
30 |
Correct |
71 ms |
84908 KB |
Output is correct |
31 |
Correct |
70 ms |
84924 KB |
Output is correct |
32 |
Correct |
1414 ms |
92676 KB |
Output is correct |
33 |
Correct |
1343 ms |
95456 KB |
Output is correct |
34 |
Correct |
1513 ms |
92624 KB |
Output is correct |
35 |
Correct |
1400 ms |
92772 KB |
Output is correct |
36 |
Correct |
1133 ms |
92536 KB |
Output is correct |
37 |
Correct |
1160 ms |
92512 KB |
Output is correct |
38 |
Correct |
1167 ms |
92496 KB |
Output is correct |
39 |
Correct |
1320 ms |
95820 KB |
Output is correct |
40 |
Correct |
1390 ms |
95548 KB |
Output is correct |
41 |
Correct |
1405 ms |
95464 KB |
Output is correct |
42 |
Correct |
1458 ms |
95420 KB |
Output is correct |
43 |
Correct |
1320 ms |
95420 KB |
Output is correct |
44 |
Correct |
1313 ms |
95440 KB |
Output is correct |
45 |
Correct |
1261 ms |
95548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
682 ms |
94712 KB |
Output is correct |
2 |
Correct |
337 ms |
88056 KB |
Output is correct |
3 |
Correct |
333 ms |
88140 KB |
Output is correct |
4 |
Correct |
343 ms |
88184 KB |
Output is correct |
5 |
Correct |
350 ms |
88184 KB |
Output is correct |
6 |
Correct |
332 ms |
88184 KB |
Output is correct |
7 |
Correct |
344 ms |
88056 KB |
Output is correct |
8 |
Correct |
68 ms |
84856 KB |
Output is correct |
9 |
Correct |
69 ms |
84856 KB |
Output is correct |
10 |
Correct |
67 ms |
84924 KB |
Output is correct |
11 |
Correct |
671 ms |
94704 KB |
Output is correct |
12 |
Correct |
678 ms |
94712 KB |
Output is correct |
13 |
Correct |
668 ms |
95096 KB |
Output is correct |
14 |
Correct |
684 ms |
95400 KB |
Output is correct |
15 |
Correct |
665 ms |
94916 KB |
Output is correct |
16 |
Correct |
693 ms |
94668 KB |
Output is correct |
17 |
Correct |
681 ms |
94548 KB |
Output is correct |
18 |
Correct |
692 ms |
94712 KB |
Output is correct |
19 |
Correct |
69 ms |
84860 KB |
Output is correct |
20 |
Correct |
67 ms |
84856 KB |
Output is correct |
21 |
Correct |
68 ms |
84856 KB |
Output is correct |
22 |
Correct |
72 ms |
84856 KB |
Output is correct |
23 |
Correct |
70 ms |
84856 KB |
Output is correct |
24 |
Correct |
70 ms |
84856 KB |
Output is correct |
25 |
Correct |
67 ms |
84856 KB |
Output is correct |
26 |
Correct |
68 ms |
84856 KB |
Output is correct |
27 |
Correct |
71 ms |
84900 KB |
Output is correct |
28 |
Correct |
69 ms |
84936 KB |
Output is correct |
29 |
Correct |
68 ms |
84916 KB |
Output is correct |
30 |
Correct |
69 ms |
84856 KB |
Output is correct |
31 |
Correct |
69 ms |
84856 KB |
Output is correct |
32 |
Correct |
70 ms |
84884 KB |
Output is correct |
33 |
Correct |
72 ms |
84960 KB |
Output is correct |
34 |
Correct |
72 ms |
84856 KB |
Output is correct |
35 |
Correct |
68 ms |
84856 KB |
Output is correct |
36 |
Correct |
69 ms |
84856 KB |
Output is correct |
37 |
Correct |
74 ms |
84856 KB |
Output is correct |
38 |
Correct |
68 ms |
84856 KB |
Output is correct |
39 |
Correct |
67 ms |
84856 KB |
Output is correct |
40 |
Correct |
484 ms |
93200 KB |
Output is correct |
41 |
Correct |
187 ms |
87548 KB |
Output is correct |
42 |
Correct |
175 ms |
87544 KB |
Output is correct |
43 |
Correct |
165 ms |
87544 KB |
Output is correct |
44 |
Correct |
189 ms |
87800 KB |
Output is correct |
45 |
Correct |
189 ms |
87800 KB |
Output is correct |
46 |
Correct |
195 ms |
87676 KB |
Output is correct |
47 |
Correct |
72 ms |
84920 KB |
Output is correct |
48 |
Correct |
70 ms |
84856 KB |
Output is correct |
49 |
Correct |
81 ms |
84840 KB |
Output is correct |
50 |
Correct |
544 ms |
91892 KB |
Output is correct |
51 |
Correct |
466 ms |
93176 KB |
Output is correct |
52 |
Correct |
586 ms |
91896 KB |
Output is correct |
53 |
Correct |
563 ms |
91768 KB |
Output is correct |
54 |
Correct |
459 ms |
93080 KB |
Output is correct |
55 |
Correct |
554 ms |
93688 KB |
Output is correct |
56 |
Correct |
578 ms |
93700 KB |
Output is correct |
57 |
Correct |
567 ms |
93956 KB |
Output is correct |
58 |
Correct |
496 ms |
93096 KB |
Output is correct |
59 |
Correct |
470 ms |
93048 KB |
Output is correct |
60 |
Correct |
489 ms |
93164 KB |
Output is correct |
61 |
Correct |
909 ms |
95952 KB |
Output is correct |
62 |
Correct |
294 ms |
88356 KB |
Output is correct |
63 |
Correct |
377 ms |
88188 KB |
Output is correct |
64 |
Correct |
350 ms |
88280 KB |
Output is correct |
65 |
Correct |
306 ms |
88280 KB |
Output is correct |
66 |
Correct |
306 ms |
88436 KB |
Output is correct |
67 |
Correct |
348 ms |
88232 KB |
Output is correct |
68 |
Correct |
74 ms |
84840 KB |
Output is correct |
69 |
Correct |
66 ms |
84984 KB |
Output is correct |
70 |
Correct |
66 ms |
84888 KB |
Output is correct |
71 |
Correct |
842 ms |
92868 KB |
Output is correct |
72 |
Correct |
772 ms |
95928 KB |
Output is correct |
73 |
Correct |
855 ms |
92780 KB |
Output is correct |
74 |
Correct |
843 ms |
92676 KB |
Output is correct |
75 |
Correct |
794 ms |
95916 KB |
Output is correct |
76 |
Correct |
844 ms |
96012 KB |
Output is correct |
77 |
Correct |
830 ms |
96000 KB |
Output is correct |
78 |
Correct |
833 ms |
96228 KB |
Output is correct |
79 |
Correct |
785 ms |
95924 KB |
Output is correct |
80 |
Correct |
835 ms |
96048 KB |
Output is correct |
81 |
Correct |
789 ms |
95920 KB |
Output is correct |
82 |
Correct |
1365 ms |
95408 KB |
Output is correct |
83 |
Correct |
294 ms |
88188 KB |
Output is correct |
84 |
Correct |
293 ms |
88184 KB |
Output is correct |
85 |
Correct |
281 ms |
88184 KB |
Output is correct |
86 |
Correct |
294 ms |
88180 KB |
Output is correct |
87 |
Correct |
300 ms |
88196 KB |
Output is correct |
88 |
Correct |
321 ms |
88156 KB |
Output is correct |
89 |
Correct |
74 ms |
84856 KB |
Output is correct |
90 |
Correct |
71 ms |
84908 KB |
Output is correct |
91 |
Correct |
70 ms |
84924 KB |
Output is correct |
92 |
Correct |
1414 ms |
92676 KB |
Output is correct |
93 |
Correct |
1343 ms |
95456 KB |
Output is correct |
94 |
Correct |
1513 ms |
92624 KB |
Output is correct |
95 |
Correct |
1400 ms |
92772 KB |
Output is correct |
96 |
Correct |
1133 ms |
92536 KB |
Output is correct |
97 |
Correct |
1160 ms |
92512 KB |
Output is correct |
98 |
Correct |
1167 ms |
92496 KB |
Output is correct |
99 |
Correct |
1320 ms |
95820 KB |
Output is correct |
100 |
Correct |
1390 ms |
95548 KB |
Output is correct |
101 |
Correct |
1405 ms |
95464 KB |
Output is correct |
102 |
Correct |
1458 ms |
95420 KB |
Output is correct |
103 |
Correct |
1320 ms |
95420 KB |
Output is correct |
104 |
Correct |
1313 ms |
95440 KB |
Output is correct |
105 |
Correct |
1261 ms |
95548 KB |
Output is correct |
106 |
Correct |
1675 ms |
96492 KB |
Output is correct |
107 |
Correct |
380 ms |
88316 KB |
Output is correct |
108 |
Correct |
331 ms |
88440 KB |
Output is correct |
109 |
Correct |
330 ms |
88312 KB |
Output is correct |
110 |
Correct |
67 ms |
84844 KB |
Output is correct |
111 |
Correct |
67 ms |
84856 KB |
Output is correct |
112 |
Correct |
71 ms |
84856 KB |
Output is correct |
113 |
Correct |
1471 ms |
95568 KB |
Output is correct |
114 |
Correct |
1447 ms |
95560 KB |
Output is correct |
115 |
Correct |
1441 ms |
95576 KB |
Output is correct |
116 |
Correct |
1333 ms |
95572 KB |
Output is correct |
117 |
Correct |
1733 ms |
96616 KB |
Output is correct |
118 |
Correct |
1319 ms |
95452 KB |
Output is correct |
119 |
Correct |
1319 ms |
95608 KB |
Output is correct |
120 |
Correct |
558 ms |
94072 KB |
Output is correct |
121 |
Correct |
570 ms |
94072 KB |
Output is correct |
122 |
Correct |
560 ms |
94072 KB |
Output is correct |
123 |
Correct |
473 ms |
93148 KB |
Output is correct |
124 |
Correct |
474 ms |
93432 KB |
Output is correct |
125 |
Correct |
475 ms |
93408 KB |
Output is correct |
126 |
Correct |
1595 ms |
93176 KB |
Output is correct |
127 |
Correct |
1578 ms |
93176 KB |
Output is correct |
128 |
Correct |
1637 ms |
96376 KB |
Output is correct |
129 |
Correct |
1607 ms |
93048 KB |
Output is correct |
130 |
Correct |
1236 ms |
93396 KB |
Output is correct |
131 |
Correct |
1223 ms |
93028 KB |
Output is correct |
132 |
Correct |
1237 ms |
93252 KB |
Output is correct |
133 |
Correct |
1606 ms |
96376 KB |
Output is correct |
134 |
Correct |
1626 ms |
96380 KB |
Output is correct |
135 |
Correct |
1587 ms |
96632 KB |
Output is correct |
136 |
Correct |
331 ms |
88424 KB |
Output is correct |
137 |
Correct |
333 ms |
88352 KB |
Output is correct |
138 |
Correct |
336 ms |
88312 KB |
Output is correct |