#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
const int N=13e5+99,S=2,inf=2e9;
int n,q,a[N],b[N],c[N],d[N],T[N],Ans[N];
vector<int> Q[N];
int seg[N][S][S];
void make(int x){
if(x==0){
f(i,0,n){
a[i]=c[i]-i;
b[i]=d[i]-i;
}
}
else{
f(i,0,n){
a[i]=c[n-i-1]-i;
b[i]=d[n-i-1]-i;
}
f(i,0,q){
if(T[i]==1){
Q[i][0]=n-Q[i][0]-1;
}
else{
Q[i][0]=n-Q[i][0];
Q[i][2]=n-Q[i][2];
}
}
}
}
void reset(){
f(i,0,S) f(j,0,S) seg[0][i][j]=(i==j ? -inf : 0);
}
void merge(int id,int u,int v){
int res[S][S];
f(i,0,S) f(j,0,S) res[i][j]=(i==j ? -inf : 0);
f(i,0,2){
f(j,0,2){
f(p,0,2){
int k=j^1;
maxm(res[i][p],seg[u][i][j]+seg[v][k][p]);
}
}
}
f(i,0,S) f(j,0,S) seg[id][i][j]=res[i][j];
}
void add(int u,int v){
int id=N-5;
f(i,0,S) f(j,0,S) seg[id][i][j]=(i==j ? -inf : 0);
seg[id][0][0]=u;
merge(0,id,0);
f(i,0,S) f(j,0,S) seg[id][i][j]=(i==j ? -inf : 0);
seg[id][1][1]=-v;
merge(0,0,id);
}
void build(int id=1,int l=0,int r=n){
if(r<=l) return ;
if(l+1==r){
seg[id][0][0]=a[l];
seg[id][1][1]=-b[l];
seg[id][0][1]=0;
seg[id][1][0]=0;
return ;
}
int mid=(l+r)>>1;
build(id<<1,l,mid);
build(id<<1|1,mid,r);
merge(id,id<<1,id<<1|1);
}
void change(int id,int l,int r,int x){
if(r<=l) return ;
if(r<=x || x<l) return ;
if(l+1==r){
seg[id][0][0]=a[l];
seg[id][1][1]=-b[l];
seg[id][0][1]=0;
seg[id][1][0]=0;
return ;
}
int mid=(l+r)>>1;
change(id<<1,l,mid,x);
change(id<<1|1,mid,r,x);
merge(id,id<<1,id<<1|1);
}
void get(int id,int l,int r,int L,int R){
if(r<=l) return ;
if(r<=L || R<=l) return ;
if(L<=l && r<=R){
merge(0,0,id);
return ;
}
int mid=(l+r)>>1;
get(id<<1,l,mid,L,R);
get(id<<1|1,mid,r,L,R);
}
void solve(){
build();
f(i,0,q){
int t,x,l,r;
if(T[i]==1){
x=Q[i][0],l=Q[i][1],r=Q[i][2];
a[x]=l-x;
b[x]=r-x;
change(1,0,n,x);
}
else{
int s,e,t,p,ans=0;
s=Q[i][0],e=Q[i][1],t=Q[i][2],p=Q[i][3];
if(s<=t){
int b1=e-s,b2=p-t;
if(s==t){
maxm(Ans[i],b1-b2);
}
else{
reset();
get(1,0,n,s,t);
add(b1,b2);
maxm(Ans[i],seg[0][0][1]);
}
}
}
}
}
main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>q; n--;
f(i,0,n){
cin>>c[i]>>d[i];
d[i]--;
}
f(i,0,q){
cin>>T[i];
if(T[i]==1){
int x,l,r;
cin>>x>>l>>r;
x--; r--;
Q[i].pb(x);
Q[i].pb(l);
Q[i].pb(r);
}
else{
int s,e,t,p;
cin>>s>>e>>t>>p;
s--,t--;
Q[i].pb(s);
Q[i].pb(e);
Q[i].pb(t);
Q[i].pb(p);
}
}
make(0);
solve();
make(1);
solve();
f(i,0,q){
if(T[i]==2){
cout<<Ans[i]<<'\n';
}
}
}
/*
3 1
0 5
0 5
2 1 3 3 3
1 2 0 1
2 1 3 3 3
*/
Compilation message
timeleap.cpp: In function 'void solve()':
timeleap.cpp:128:16: warning: unused variable 'ans' [-Wunused-variable]
128 | int s,e,t,p,ans=0;
| ^~~
timeleap.cpp:120:7: warning: unused variable 't' [-Wunused-variable]
120 | int t,x,l,r;
| ^
timeleap.cpp: At global scope:
timeleap.cpp:147:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
147 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
30796 KB |
Output is correct |
2 |
Correct |
15 ms |
30904 KB |
Output is correct |
3 |
Correct |
16 ms |
30896 KB |
Output is correct |
4 |
Correct |
16 ms |
30884 KB |
Output is correct |
5 |
Correct |
16 ms |
30796 KB |
Output is correct |
6 |
Correct |
16 ms |
30796 KB |
Output is correct |
7 |
Correct |
20 ms |
30796 KB |
Output is correct |
8 |
Correct |
16 ms |
30772 KB |
Output is correct |
9 |
Correct |
16 ms |
30856 KB |
Output is correct |
10 |
Correct |
19 ms |
30796 KB |
Output is correct |
11 |
Correct |
17 ms |
31060 KB |
Output is correct |
12 |
Correct |
17 ms |
31068 KB |
Output is correct |
13 |
Correct |
17 ms |
31052 KB |
Output is correct |
14 |
Correct |
19 ms |
31060 KB |
Output is correct |
15 |
Correct |
17 ms |
31024 KB |
Output is correct |
16 |
Correct |
17 ms |
31052 KB |
Output is correct |
17 |
Correct |
17 ms |
30972 KB |
Output is correct |
18 |
Correct |
17 ms |
31052 KB |
Output is correct |
19 |
Correct |
21 ms |
31052 KB |
Output is correct |
20 |
Correct |
17 ms |
31064 KB |
Output is correct |
21 |
Correct |
20 ms |
31020 KB |
Output is correct |
22 |
Correct |
21 ms |
31036 KB |
Output is correct |
23 |
Correct |
17 ms |
31068 KB |
Output is correct |
24 |
Correct |
16 ms |
30952 KB |
Output is correct |
25 |
Correct |
17 ms |
31052 KB |
Output is correct |
26 |
Correct |
17 ms |
31052 KB |
Output is correct |
27 |
Correct |
17 ms |
31060 KB |
Output is correct |
28 |
Correct |
17 ms |
31052 KB |
Output is correct |
29 |
Correct |
17 ms |
30964 KB |
Output is correct |
30 |
Correct |
17 ms |
31072 KB |
Output is correct |
31 |
Correct |
18 ms |
31032 KB |
Output is correct |
32 |
Correct |
17 ms |
31008 KB |
Output is correct |
33 |
Correct |
17 ms |
31064 KB |
Output is correct |
34 |
Correct |
17 ms |
31020 KB |
Output is correct |
35 |
Correct |
18 ms |
30976 KB |
Output is correct |
36 |
Correct |
17 ms |
31052 KB |
Output is correct |
37 |
Correct |
17 ms |
31052 KB |
Output is correct |
38 |
Correct |
17 ms |
31052 KB |
Output is correct |
39 |
Correct |
17 ms |
30964 KB |
Output is correct |
40 |
Correct |
17 ms |
31056 KB |
Output is correct |
41 |
Correct |
16 ms |
30760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
458 ms |
95288 KB |
Output is correct |
2 |
Correct |
450 ms |
78384 KB |
Output is correct |
3 |
Correct |
462 ms |
78532 KB |
Output is correct |
4 |
Correct |
431 ms |
78160 KB |
Output is correct |
5 |
Correct |
450 ms |
95252 KB |
Output is correct |
6 |
Correct |
473 ms |
95116 KB |
Output is correct |
7 |
Correct |
460 ms |
95556 KB |
Output is correct |
8 |
Correct |
455 ms |
95880 KB |
Output is correct |
9 |
Correct |
446 ms |
78284 KB |
Output is correct |
10 |
Correct |
506 ms |
95428 KB |
Output is correct |
11 |
Correct |
470 ms |
95308 KB |
Output is correct |
12 |
Correct |
460 ms |
95964 KB |
Output is correct |
13 |
Correct |
470 ms |
96240 KB |
Output is correct |
14 |
Correct |
16 ms |
30820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
30796 KB |
Output is correct |
2 |
Correct |
15 ms |
30904 KB |
Output is correct |
3 |
Correct |
16 ms |
30896 KB |
Output is correct |
4 |
Correct |
16 ms |
30884 KB |
Output is correct |
5 |
Correct |
16 ms |
30796 KB |
Output is correct |
6 |
Correct |
16 ms |
30796 KB |
Output is correct |
7 |
Correct |
20 ms |
30796 KB |
Output is correct |
8 |
Correct |
16 ms |
30772 KB |
Output is correct |
9 |
Correct |
16 ms |
30856 KB |
Output is correct |
10 |
Correct |
19 ms |
30796 KB |
Output is correct |
11 |
Correct |
17 ms |
31060 KB |
Output is correct |
12 |
Correct |
17 ms |
31068 KB |
Output is correct |
13 |
Correct |
17 ms |
31052 KB |
Output is correct |
14 |
Correct |
19 ms |
31060 KB |
Output is correct |
15 |
Correct |
17 ms |
31024 KB |
Output is correct |
16 |
Correct |
17 ms |
31052 KB |
Output is correct |
17 |
Correct |
17 ms |
30972 KB |
Output is correct |
18 |
Correct |
17 ms |
31052 KB |
Output is correct |
19 |
Correct |
21 ms |
31052 KB |
Output is correct |
20 |
Correct |
17 ms |
31064 KB |
Output is correct |
21 |
Correct |
20 ms |
31020 KB |
Output is correct |
22 |
Correct |
21 ms |
31036 KB |
Output is correct |
23 |
Correct |
17 ms |
31068 KB |
Output is correct |
24 |
Correct |
16 ms |
30952 KB |
Output is correct |
25 |
Correct |
17 ms |
31052 KB |
Output is correct |
26 |
Correct |
17 ms |
31052 KB |
Output is correct |
27 |
Correct |
17 ms |
31060 KB |
Output is correct |
28 |
Correct |
17 ms |
31052 KB |
Output is correct |
29 |
Correct |
17 ms |
30964 KB |
Output is correct |
30 |
Correct |
17 ms |
31072 KB |
Output is correct |
31 |
Correct |
18 ms |
31032 KB |
Output is correct |
32 |
Correct |
17 ms |
31008 KB |
Output is correct |
33 |
Correct |
17 ms |
31064 KB |
Output is correct |
34 |
Correct |
17 ms |
31020 KB |
Output is correct |
35 |
Correct |
18 ms |
30976 KB |
Output is correct |
36 |
Correct |
17 ms |
31052 KB |
Output is correct |
37 |
Correct |
17 ms |
31052 KB |
Output is correct |
38 |
Correct |
17 ms |
31052 KB |
Output is correct |
39 |
Correct |
17 ms |
30964 KB |
Output is correct |
40 |
Correct |
17 ms |
31056 KB |
Output is correct |
41 |
Correct |
16 ms |
30760 KB |
Output is correct |
42 |
Correct |
458 ms |
95288 KB |
Output is correct |
43 |
Correct |
450 ms |
78384 KB |
Output is correct |
44 |
Correct |
462 ms |
78532 KB |
Output is correct |
45 |
Correct |
431 ms |
78160 KB |
Output is correct |
46 |
Correct |
450 ms |
95252 KB |
Output is correct |
47 |
Correct |
473 ms |
95116 KB |
Output is correct |
48 |
Correct |
460 ms |
95556 KB |
Output is correct |
49 |
Correct |
455 ms |
95880 KB |
Output is correct |
50 |
Correct |
446 ms |
78284 KB |
Output is correct |
51 |
Correct |
506 ms |
95428 KB |
Output is correct |
52 |
Correct |
470 ms |
95308 KB |
Output is correct |
53 |
Correct |
460 ms |
95964 KB |
Output is correct |
54 |
Correct |
470 ms |
96240 KB |
Output is correct |
55 |
Correct |
16 ms |
30820 KB |
Output is correct |
56 |
Correct |
518 ms |
107584 KB |
Output is correct |
57 |
Correct |
491 ms |
90208 KB |
Output is correct |
58 |
Correct |
509 ms |
108040 KB |
Output is correct |
59 |
Correct |
520 ms |
108252 KB |
Output is correct |
60 |
Correct |
484 ms |
90584 KB |
Output is correct |
61 |
Correct |
566 ms |
108616 KB |
Output is correct |
62 |
Correct |
507 ms |
108524 KB |
Output is correct |
63 |
Correct |
557 ms |
108508 KB |
Output is correct |
64 |
Correct |
518 ms |
108608 KB |
Output is correct |
65 |
Correct |
517 ms |
107888 KB |
Output is correct |
66 |
Correct |
510 ms |
107956 KB |
Output is correct |
67 |
Correct |
517 ms |
108536 KB |
Output is correct |
68 |
Correct |
536 ms |
100052 KB |
Output is correct |
69 |
Correct |
582 ms |
108872 KB |
Output is correct |
70 |
Correct |
519 ms |
90732 KB |
Output is correct |
71 |
Correct |
560 ms |
89624 KB |
Output is correct |
72 |
Correct |
499 ms |
95816 KB |
Output is correct |
73 |
Correct |
535 ms |
108148 KB |
Output is correct |
74 |
Correct |
514 ms |
108344 KB |
Output is correct |
75 |
Correct |
529 ms |
108592 KB |
Output is correct |
76 |
Correct |
543 ms |
109208 KB |
Output is correct |
77 |
Correct |
15 ms |
30800 KB |
Output is correct |