#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma")
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif
inline char readchar(){
const int maxn=1000000;
static char buf[maxn],*p=buf,*q=buf;
if(p==q&&(q=(p=buf)+fread(buf,1,maxn,stdin))==buf) return EOF;
else return *p++;
}
inline int readint(){
int c=readchar(),x=0,neg=0;
while((c<'0'||c>'9')&&c!='-'&&c!=EOF) c=readchar();
if(c=='-') neg=1,c=readchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=readchar();
return neg?-x:x;
}
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
const int maxn=300005;
//i_am_noob
int n,q,l[maxn],r[maxn];
#define event array<int,4>
event Merge(event x, event y){
event res;
res[0]=min(x[1],x[0]+max(0ll,y[0]-x[2]));
res[1]=max(x[0],x[1]-max(0ll,x[2]+x[1]-x[0]-y[1]));
res[2]=min(max(y[2]+x[2]-y[0],y[2]),y[2]+y[1]-y[0]);
res[3]=x[3]+y[3]+max(0ll,x[2]-y[1]);
return res;
}
struct segtree{
event val[4*maxn],e;
void pull(int k){val[k]=Merge(val[k<<1],val[k<<1|1]);}
void build(int k, int l, int r){
if(l==r){
val[k]=e;
return;
}
int mid=l+r>>1;
build(k<<1,l,mid),build(k<<1|1,mid+1,r);
pull(k);
}
segtree(){
e={-inf,inf,-inf,0};
build(1,0,maxn-1);
}
void modify(int k, int l, int r, int p, event x){
if(l==r){
val[k]=x;
return;
}
int mid=l+r>>1;
if(p<=mid) modify(k<<1,l,mid,p,x);
else modify(k<<1|1,mid+1,r,p,x);
pull(k);
}
event query(int k, int l, int r, int ql, int qr){
if(ql>r||qr<l) return e;
if(ql<=l&&qr>=r) return val[k];
int mid=l+r>>1;
return Merge(query(k<<1,l,mid,ql,qr),query(k<<1|1,mid+1,r,ql,qr));
}
inline void mo(int p, event x){modify(1,0,maxn-1,p,x);}
inline event qu(int ql, int qr){return query(1,0,maxn-1,ql,qr);}
}tree1,tree2;
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
#ifdef i_am_noob
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
freopen("output2.txt","w",stderr);
#endif
cin >> n >> q;
rep(n-1) cin >> l[i] >> r[i];
rep(n-1){
r[i]--;
tree1.mo(i,{l[i]-i,r[i]-i,l[i]-i,0});
tree2.mo(n-2-i,{l[i]-(n-2-i),r[i]-(n-2-i),l[i]-(n-2-i),0});
}
while(q--){
int op;
cin >> op;
if(op==1){
int p,s,e;
cin >> p >> s >> e;
p--,e--;
tree1.mo(p,{s-p,e-p,s-p,0});
tree2.mo(n-2-p,{s-(n-2-p),e-(n-2-p),s-(n-2-p),0});
}
else{
int a,b,c,d;
cin >> a >> b >> c >> d;
a--,c--;
event s,e,tmp;
if(c>a){
b-=a,d-=c;
tmp=tree1.qu(a,c-1);
}
else{
b-=n-1-a,d-=n-1-c;
tmp=tree2.qu(n-1-a,n-2-c);
}
s={b,b,b,0},e={d,d,d,0};
tmp=Merge(s,tmp);
tmp=Merge(tmp,e);
cout << tmp[3] << "\n";
}
}
return 0;
}
Compilation message
timeleap.cpp: In member function 'void segtree::build(long long int, long long int, long long int)':
timeleap.cpp:70:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
70 | int mid=l+r>>1;
| ~^~
timeleap.cpp: In member function 'void segtree::modify(long long int, long long int, long long int, long long int, std::array<long long int, 4>)':
timeleap.cpp:83:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
83 | int mid=l+r>>1;
| ~^~
timeleap.cpp: In member function 'std::array<long long int, 4> segtree::query(long long int, long long int, long long int, long long int, long long int)':
timeleap.cpp:91:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
91 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
66028 KB |
Output is correct |
2 |
Correct |
39 ms |
66028 KB |
Output is correct |
3 |
Correct |
39 ms |
66028 KB |
Output is correct |
4 |
Correct |
38 ms |
66028 KB |
Output is correct |
5 |
Correct |
40 ms |
66028 KB |
Output is correct |
6 |
Correct |
39 ms |
66028 KB |
Output is correct |
7 |
Correct |
42 ms |
66028 KB |
Output is correct |
8 |
Correct |
41 ms |
66176 KB |
Output is correct |
9 |
Correct |
39 ms |
66028 KB |
Output is correct |
10 |
Correct |
39 ms |
66028 KB |
Output is correct |
11 |
Correct |
40 ms |
66156 KB |
Output is correct |
12 |
Correct |
42 ms |
66284 KB |
Output is correct |
13 |
Correct |
40 ms |
66156 KB |
Output is correct |
14 |
Correct |
42 ms |
66156 KB |
Output is correct |
15 |
Correct |
40 ms |
66156 KB |
Output is correct |
16 |
Correct |
41 ms |
66156 KB |
Output is correct |
17 |
Correct |
41 ms |
66156 KB |
Output is correct |
18 |
Correct |
40 ms |
66156 KB |
Output is correct |
19 |
Correct |
41 ms |
66172 KB |
Output is correct |
20 |
Correct |
46 ms |
66156 KB |
Output is correct |
21 |
Correct |
41 ms |
66156 KB |
Output is correct |
22 |
Correct |
42 ms |
66156 KB |
Output is correct |
23 |
Correct |
41 ms |
66156 KB |
Output is correct |
24 |
Correct |
40 ms |
66028 KB |
Output is correct |
25 |
Correct |
42 ms |
66156 KB |
Output is correct |
26 |
Correct |
41 ms |
66156 KB |
Output is correct |
27 |
Correct |
43 ms |
66156 KB |
Output is correct |
28 |
Correct |
45 ms |
66156 KB |
Output is correct |
29 |
Correct |
42 ms |
66156 KB |
Output is correct |
30 |
Correct |
44 ms |
66156 KB |
Output is correct |
31 |
Correct |
44 ms |
66156 KB |
Output is correct |
32 |
Correct |
43 ms |
66156 KB |
Output is correct |
33 |
Correct |
41 ms |
66156 KB |
Output is correct |
34 |
Correct |
42 ms |
66156 KB |
Output is correct |
35 |
Correct |
41 ms |
66156 KB |
Output is correct |
36 |
Correct |
41 ms |
66156 KB |
Output is correct |
37 |
Correct |
42 ms |
66156 KB |
Output is correct |
38 |
Correct |
42 ms |
66156 KB |
Output is correct |
39 |
Correct |
40 ms |
66156 KB |
Output is correct |
40 |
Correct |
41 ms |
66156 KB |
Output is correct |
41 |
Correct |
39 ms |
66028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
816 ms |
76140 KB |
Output is correct |
2 |
Correct |
820 ms |
75948 KB |
Output is correct |
3 |
Correct |
777 ms |
76012 KB |
Output is correct |
4 |
Correct |
770 ms |
75756 KB |
Output is correct |
5 |
Correct |
784 ms |
75884 KB |
Output is correct |
6 |
Correct |
794 ms |
76012 KB |
Output is correct |
7 |
Correct |
806 ms |
76076 KB |
Output is correct |
8 |
Correct |
823 ms |
76396 KB |
Output is correct |
9 |
Correct |
776 ms |
75884 KB |
Output is correct |
10 |
Correct |
815 ms |
75952 KB |
Output is correct |
11 |
Correct |
819 ms |
76012 KB |
Output is correct |
12 |
Correct |
826 ms |
75884 KB |
Output is correct |
13 |
Correct |
832 ms |
75756 KB |
Output is correct |
14 |
Correct |
39 ms |
66028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
66028 KB |
Output is correct |
2 |
Correct |
39 ms |
66028 KB |
Output is correct |
3 |
Correct |
39 ms |
66028 KB |
Output is correct |
4 |
Correct |
38 ms |
66028 KB |
Output is correct |
5 |
Correct |
40 ms |
66028 KB |
Output is correct |
6 |
Correct |
39 ms |
66028 KB |
Output is correct |
7 |
Correct |
42 ms |
66028 KB |
Output is correct |
8 |
Correct |
41 ms |
66176 KB |
Output is correct |
9 |
Correct |
39 ms |
66028 KB |
Output is correct |
10 |
Correct |
39 ms |
66028 KB |
Output is correct |
11 |
Correct |
40 ms |
66156 KB |
Output is correct |
12 |
Correct |
42 ms |
66284 KB |
Output is correct |
13 |
Correct |
40 ms |
66156 KB |
Output is correct |
14 |
Correct |
42 ms |
66156 KB |
Output is correct |
15 |
Correct |
40 ms |
66156 KB |
Output is correct |
16 |
Correct |
41 ms |
66156 KB |
Output is correct |
17 |
Correct |
41 ms |
66156 KB |
Output is correct |
18 |
Correct |
40 ms |
66156 KB |
Output is correct |
19 |
Correct |
41 ms |
66172 KB |
Output is correct |
20 |
Correct |
46 ms |
66156 KB |
Output is correct |
21 |
Correct |
41 ms |
66156 KB |
Output is correct |
22 |
Correct |
42 ms |
66156 KB |
Output is correct |
23 |
Correct |
41 ms |
66156 KB |
Output is correct |
24 |
Correct |
40 ms |
66028 KB |
Output is correct |
25 |
Correct |
42 ms |
66156 KB |
Output is correct |
26 |
Correct |
41 ms |
66156 KB |
Output is correct |
27 |
Correct |
43 ms |
66156 KB |
Output is correct |
28 |
Correct |
45 ms |
66156 KB |
Output is correct |
29 |
Correct |
42 ms |
66156 KB |
Output is correct |
30 |
Correct |
44 ms |
66156 KB |
Output is correct |
31 |
Correct |
44 ms |
66156 KB |
Output is correct |
32 |
Correct |
43 ms |
66156 KB |
Output is correct |
33 |
Correct |
41 ms |
66156 KB |
Output is correct |
34 |
Correct |
42 ms |
66156 KB |
Output is correct |
35 |
Correct |
41 ms |
66156 KB |
Output is correct |
36 |
Correct |
41 ms |
66156 KB |
Output is correct |
37 |
Correct |
42 ms |
66156 KB |
Output is correct |
38 |
Correct |
42 ms |
66156 KB |
Output is correct |
39 |
Correct |
40 ms |
66156 KB |
Output is correct |
40 |
Correct |
41 ms |
66156 KB |
Output is correct |
41 |
Correct |
39 ms |
66028 KB |
Output is correct |
42 |
Correct |
816 ms |
76140 KB |
Output is correct |
43 |
Correct |
820 ms |
75948 KB |
Output is correct |
44 |
Correct |
777 ms |
76012 KB |
Output is correct |
45 |
Correct |
770 ms |
75756 KB |
Output is correct |
46 |
Correct |
784 ms |
75884 KB |
Output is correct |
47 |
Correct |
794 ms |
76012 KB |
Output is correct |
48 |
Correct |
806 ms |
76076 KB |
Output is correct |
49 |
Correct |
823 ms |
76396 KB |
Output is correct |
50 |
Correct |
776 ms |
75884 KB |
Output is correct |
51 |
Correct |
815 ms |
75952 KB |
Output is correct |
52 |
Correct |
819 ms |
76012 KB |
Output is correct |
53 |
Correct |
826 ms |
75884 KB |
Output is correct |
54 |
Correct |
832 ms |
75756 KB |
Output is correct |
55 |
Correct |
39 ms |
66028 KB |
Output is correct |
56 |
Correct |
777 ms |
73452 KB |
Output is correct |
57 |
Correct |
745 ms |
73196 KB |
Output is correct |
58 |
Correct |
770 ms |
73580 KB |
Output is correct |
59 |
Correct |
777 ms |
73484 KB |
Output is correct |
60 |
Correct |
768 ms |
73196 KB |
Output is correct |
61 |
Correct |
774 ms |
73580 KB |
Output is correct |
62 |
Correct |
812 ms |
73496 KB |
Output is correct |
63 |
Correct |
791 ms |
73276 KB |
Output is correct |
64 |
Correct |
810 ms |
73324 KB |
Output is correct |
65 |
Correct |
764 ms |
73196 KB |
Output is correct |
66 |
Correct |
768 ms |
73196 KB |
Output is correct |
67 |
Correct |
795 ms |
73292 KB |
Output is correct |
68 |
Correct |
757 ms |
73068 KB |
Output is correct |
69 |
Correct |
814 ms |
73484 KB |
Output is correct |
70 |
Correct |
760 ms |
72940 KB |
Output is correct |
71 |
Correct |
752 ms |
72812 KB |
Output is correct |
72 |
Correct |
761 ms |
72812 KB |
Output is correct |
73 |
Correct |
792 ms |
73252 KB |
Output is correct |
74 |
Correct |
777 ms |
73196 KB |
Output is correct |
75 |
Correct |
786 ms |
73176 KB |
Output is correct |
76 |
Correct |
783 ms |
73180 KB |
Output is correct |
77 |
Correct |
39 ms |
66028 KB |
Output is correct |