#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(p>r||p<l) return;
if(l==r){
val[k]=x;
return;
}
int mid=l+r>>1;
modify(k<<1,l,mid,p,x),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:84:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
84 | 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;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
66028 KB |
Output is correct |
2 |
Correct |
42 ms |
66028 KB |
Output is correct |
3 |
Correct |
42 ms |
66028 KB |
Output is correct |
4 |
Correct |
42 ms |
66028 KB |
Output is correct |
5 |
Correct |
41 ms |
66028 KB |
Output is correct |
6 |
Correct |
41 ms |
66028 KB |
Output is correct |
7 |
Correct |
43 ms |
66028 KB |
Output is correct |
8 |
Correct |
42 ms |
66028 KB |
Output is correct |
9 |
Correct |
41 ms |
66156 KB |
Output is correct |
10 |
Correct |
41 ms |
66028 KB |
Output is correct |
11 |
Correct |
45 ms |
66156 KB |
Output is correct |
12 |
Correct |
43 ms |
66156 KB |
Output is correct |
13 |
Correct |
43 ms |
66156 KB |
Output is correct |
14 |
Correct |
43 ms |
66156 KB |
Output is correct |
15 |
Correct |
44 ms |
66156 KB |
Output is correct |
16 |
Correct |
44 ms |
66156 KB |
Output is correct |
17 |
Correct |
44 ms |
66156 KB |
Output is correct |
18 |
Correct |
43 ms |
66156 KB |
Output is correct |
19 |
Correct |
44 ms |
66156 KB |
Output is correct |
20 |
Correct |
44 ms |
66284 KB |
Output is correct |
21 |
Correct |
44 ms |
66156 KB |
Output is correct |
22 |
Correct |
44 ms |
66156 KB |
Output is correct |
23 |
Correct |
44 ms |
66156 KB |
Output is correct |
24 |
Correct |
44 ms |
66156 KB |
Output is correct |
25 |
Correct |
43 ms |
66156 KB |
Output is correct |
26 |
Correct |
44 ms |
66156 KB |
Output is correct |
27 |
Correct |
43 ms |
66156 KB |
Output is correct |
28 |
Correct |
46 ms |
66156 KB |
Output is correct |
29 |
Correct |
52 ms |
66156 KB |
Output is correct |
30 |
Correct |
44 ms |
66156 KB |
Output is correct |
31 |
Correct |
44 ms |
66148 KB |
Output is correct |
32 |
Correct |
47 ms |
66156 KB |
Output is correct |
33 |
Correct |
43 ms |
66156 KB |
Output is correct |
34 |
Correct |
43 ms |
66156 KB |
Output is correct |
35 |
Correct |
44 ms |
66156 KB |
Output is correct |
36 |
Correct |
44 ms |
66156 KB |
Output is correct |
37 |
Correct |
44 ms |
66092 KB |
Output is correct |
38 |
Correct |
44 ms |
66156 KB |
Output is correct |
39 |
Correct |
43 ms |
66156 KB |
Output is correct |
40 |
Correct |
44 ms |
66156 KB |
Output is correct |
41 |
Correct |
42 ms |
66028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
851 ms |
90092 KB |
Output is correct |
2 |
Correct |
832 ms |
89540 KB |
Output is correct |
3 |
Correct |
833 ms |
89852 KB |
Output is correct |
4 |
Correct |
826 ms |
89576 KB |
Output is correct |
5 |
Correct |
856 ms |
90092 KB |
Output is correct |
6 |
Correct |
905 ms |
90104 KB |
Output is correct |
7 |
Correct |
857 ms |
90348 KB |
Output is correct |
8 |
Correct |
862 ms |
90920 KB |
Output is correct |
9 |
Correct |
828 ms |
89708 KB |
Output is correct |
10 |
Correct |
862 ms |
90348 KB |
Output is correct |
11 |
Correct |
846 ms |
90220 KB |
Output is correct |
12 |
Correct |
940 ms |
91140 KB |
Output is correct |
13 |
Correct |
882 ms |
91240 KB |
Output is correct |
14 |
Correct |
41 ms |
66028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
66028 KB |
Output is correct |
2 |
Correct |
42 ms |
66028 KB |
Output is correct |
3 |
Correct |
42 ms |
66028 KB |
Output is correct |
4 |
Correct |
42 ms |
66028 KB |
Output is correct |
5 |
Correct |
41 ms |
66028 KB |
Output is correct |
6 |
Correct |
41 ms |
66028 KB |
Output is correct |
7 |
Correct |
43 ms |
66028 KB |
Output is correct |
8 |
Correct |
42 ms |
66028 KB |
Output is correct |
9 |
Correct |
41 ms |
66156 KB |
Output is correct |
10 |
Correct |
41 ms |
66028 KB |
Output is correct |
11 |
Correct |
45 ms |
66156 KB |
Output is correct |
12 |
Correct |
43 ms |
66156 KB |
Output is correct |
13 |
Correct |
43 ms |
66156 KB |
Output is correct |
14 |
Correct |
43 ms |
66156 KB |
Output is correct |
15 |
Correct |
44 ms |
66156 KB |
Output is correct |
16 |
Correct |
44 ms |
66156 KB |
Output is correct |
17 |
Correct |
44 ms |
66156 KB |
Output is correct |
18 |
Correct |
43 ms |
66156 KB |
Output is correct |
19 |
Correct |
44 ms |
66156 KB |
Output is correct |
20 |
Correct |
44 ms |
66284 KB |
Output is correct |
21 |
Correct |
44 ms |
66156 KB |
Output is correct |
22 |
Correct |
44 ms |
66156 KB |
Output is correct |
23 |
Correct |
44 ms |
66156 KB |
Output is correct |
24 |
Correct |
44 ms |
66156 KB |
Output is correct |
25 |
Correct |
43 ms |
66156 KB |
Output is correct |
26 |
Correct |
44 ms |
66156 KB |
Output is correct |
27 |
Correct |
43 ms |
66156 KB |
Output is correct |
28 |
Correct |
46 ms |
66156 KB |
Output is correct |
29 |
Correct |
52 ms |
66156 KB |
Output is correct |
30 |
Correct |
44 ms |
66156 KB |
Output is correct |
31 |
Correct |
44 ms |
66148 KB |
Output is correct |
32 |
Correct |
47 ms |
66156 KB |
Output is correct |
33 |
Correct |
43 ms |
66156 KB |
Output is correct |
34 |
Correct |
43 ms |
66156 KB |
Output is correct |
35 |
Correct |
44 ms |
66156 KB |
Output is correct |
36 |
Correct |
44 ms |
66156 KB |
Output is correct |
37 |
Correct |
44 ms |
66092 KB |
Output is correct |
38 |
Correct |
44 ms |
66156 KB |
Output is correct |
39 |
Correct |
43 ms |
66156 KB |
Output is correct |
40 |
Correct |
44 ms |
66156 KB |
Output is correct |
41 |
Correct |
42 ms |
66028 KB |
Output is correct |
42 |
Correct |
851 ms |
90092 KB |
Output is correct |
43 |
Correct |
832 ms |
89540 KB |
Output is correct |
44 |
Correct |
833 ms |
89852 KB |
Output is correct |
45 |
Correct |
826 ms |
89576 KB |
Output is correct |
46 |
Correct |
856 ms |
90092 KB |
Output is correct |
47 |
Correct |
905 ms |
90104 KB |
Output is correct |
48 |
Correct |
857 ms |
90348 KB |
Output is correct |
49 |
Correct |
862 ms |
90920 KB |
Output is correct |
50 |
Correct |
828 ms |
89708 KB |
Output is correct |
51 |
Correct |
862 ms |
90348 KB |
Output is correct |
52 |
Correct |
846 ms |
90220 KB |
Output is correct |
53 |
Correct |
940 ms |
91140 KB |
Output is correct |
54 |
Correct |
882 ms |
91240 KB |
Output is correct |
55 |
Correct |
41 ms |
66028 KB |
Output is correct |
56 |
Correct |
855 ms |
87020 KB |
Output is correct |
57 |
Correct |
833 ms |
86252 KB |
Output is correct |
58 |
Correct |
860 ms |
87344 KB |
Output is correct |
59 |
Correct |
876 ms |
87276 KB |
Output is correct |
60 |
Correct |
853 ms |
86764 KB |
Output is correct |
61 |
Correct |
893 ms |
87788 KB |
Output is correct |
62 |
Correct |
883 ms |
87616 KB |
Output is correct |
63 |
Correct |
881 ms |
87660 KB |
Output is correct |
64 |
Correct |
894 ms |
87656 KB |
Output is correct |
65 |
Correct |
878 ms |
87064 KB |
Output is correct |
66 |
Correct |
871 ms |
87148 KB |
Output is correct |
67 |
Correct |
882 ms |
87532 KB |
Output is correct |
68 |
Correct |
923 ms |
86508 KB |
Output is correct |
69 |
Correct |
899 ms |
87752 KB |
Output is correct |
70 |
Correct |
867 ms |
86636 KB |
Output is correct |
71 |
Correct |
823 ms |
85868 KB |
Output is correct |
72 |
Correct |
856 ms |
86252 KB |
Output is correct |
73 |
Correct |
877 ms |
87148 KB |
Output is correct |
74 |
Correct |
901 ms |
87220 KB |
Output is correct |
75 |
Correct |
894 ms |
87660 KB |
Output is correct |
76 |
Correct |
903 ms |
88252 KB |
Output is correct |
77 |
Correct |
41 ms |
66028 KB |
Output is correct |