//https://www.instagram.com/_modwwe/
#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2")
#include<bits/stdc++.h>
#define int long long
//#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
const int inf=1e18;
const int mod2=1e9+7;
const int mod1=998244353;
struct icd
{
int a,b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
struct ie
{
int a,b,c, d,e,f;
};
int n,m,s1,s2,s4,s3,sf,k,r,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,dem=0,l,l2,r2;
int i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
// fin(task),fou(task);
#endif
NHP
/// cin>>s1;
// modwwe
phongbeo();
}
id ss,ss2;
ib a[300001];
ib b[300001];
id mer(id x,id y,int c)
{
id s;
/// a.d= if(l+a.d) b=b -> l+a.d+x ->b=b+x
///a.a= if(l+a.a) c=c -> l+a.a+x ->c=c+x
/// a.a=min(x.a,y.a+x.d)
/// a.d=x.d+y.d
if(x.b>=c)
{
s2=x.b-c;
s.c=x.c+y.c;
///cout<<y.d<<" "<<y.a,down
if(s2>y.a)
{
s.c+=s2-y.a;
y.b-=s2-y.a;
y.a=0;
}
else y.a-=s2;
s.b=y.b;
if(s2>y.d)
{
s.b+=s2-y.d;
y.d=0;
}
else y.d-=s2;
}
else
{
s.b=y.b;
x.d+=c-x.b;
s.c=x.c+y.c;
}
s.a=min(x.a,y.a+x.d);
s.d=x.d+y.d;
s.d=min(s.d,s.a);
return s;
}
struct IT
{ id t[1200001];
void build(int node,int l,int r)
{
if(l==r)
{
t[node].a=a[l].b-a[l].a;
t[node].b=a[l].a+1;
t[node].c=0;
t[node].d=0;
return;
}
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
t[node]=mer(t[node<<1],t[node<<1|1],a[mid+1].a);
}
void upd(int node,int l,int r,int l1)
{
if(l==r)
{
t[node].a=a[l].b-a[l].a;
t[node].b=a[l].a+1;
t[node].c=0;
t[node].d=0;
return;
}
int mid=l+r>>1;
if(l1<=mid)upd(node<<1,l,mid,l1);
else upd(node<<1|1,mid+1,r,l1);
t[node]=mer(t[node<<1],t[node<<1|1],a[mid+1].a);
}
void get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return;
if(l>=l1&&r<=r1) {
ss=mer(ss,t[node],a[l].a);return;}
int mid=l+r>>1;
get(node<<1,l,mid,l1,r1);
get(node<<1|1,mid+1,r,l1,r1);
}
}st;
struct IT2
{ id t[1200001];
void build(int node,int l,int r)
{
if(l==r)
{
t[node].a=b[l].b-b[l].a;
t[node].b=b[l].a+1;
t[node].c=0;
t[node].d=0;
return;
}
int mid=l+r>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
t[node]=mer(t[node<<1],t[node<<1|1],b[mid+1].a);
}
void upd(int node,int l,int r,int l1)
{
if(l==r)
{
t[node].a=b[l].b-b[l].a;
t[node].b=b[l].a+1;
t[node].c=0;
t[node].d=0;
return;
}
int mid=l+r>>1;
if(l1<=mid)upd(node<<1,l,mid,l1);
else upd(node<<1|1,mid+1,r,l1);
t[node]=mer(t[node<<1],t[node<<1|1],b[mid+1].a);
}
void get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return;
if(l>=l1&&r<=r1) {
ss=mer(ss,t[node],b[l].a);return;}
int mid=l+r>>1;
get(node<<1,l,mid,l1,r1);
get(node<<1|1,mid+1,r,l1,r1);
}
}st2;
void phongbeo()
{
cin>>n>>m;
for(int i=1; i<n; i++)
cin>>a[i].a>>a[i].b,a[i].b--,b[n-i]=a[i];
if(n!=1) st.build(1,1,n-1);
if(n!=1)st2.build(1,1,n-1);
while(m--)
{
cin>>l;
if(l==1)
{
cin>>l>>s2>>s3;
a[l]={s2,s3-1};
b[n-l]=a[l];
if(n!=1) st.upd(1,1,n-1,l);
if(n!=1)st2.upd(1,1,n-1,n-l);
}
else
{
cin>>l>>r>>l2>>r2;
if(l==l2) cout<<max(0ll,r-r2);
else{
ss2={r2,1,0,0};
ss={0,r,0,0};
if(l<=l2) st.get(1,1,n-1,l,l2-1);
else {l=n-l+1;l2=n-l2+1;
st2.get(1,1,n-1,l,l2-1);
}
cout<<mer(ss,ss2,0).c;}
down
}
}
}
Compilation message
timeleap.cpp:48:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
48 | main()
| ^~~~
timeleap.cpp: In member function 'void IT::build(long long int, long long int, long long int)':
timeleap.cpp:112:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
112 | int mid=l+r>>1;
| ~^~
timeleap.cpp: In member function 'void IT::upd(long long int, long long int, long long int, long long int)':
timeleap.cpp:127:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
127 | int mid=l+r>>1;
| ~^~
timeleap.cpp: In member function 'void IT::get(long long int, long long int, long long int, long long int, long long int)':
timeleap.cpp:137:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
137 | int mid=l+r>>1;
| ~^~
timeleap.cpp: In member function 'void IT2::build(long long int, long long int, long long int)':
timeleap.cpp:156:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
156 | int mid=l+r>>1;
| ~^~
timeleap.cpp: In member function 'void IT2::upd(long long int, long long int, long long int, long long int)':
timeleap.cpp:171:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
171 | int mid=l+r>>1;
| ~^~
timeleap.cpp: In member function 'void IT2::get(long long int, long long int, long long int, long long int, long long int)':
timeleap.cpp:181:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
181 | int mid=l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
660 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
480 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
600 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
360 ms |
94288 KB |
Output is correct |
2 |
Correct |
361 ms |
60620 KB |
Output is correct |
3 |
Correct |
414 ms |
60752 KB |
Output is correct |
4 |
Correct |
343 ms |
60496 KB |
Output is correct |
5 |
Correct |
410 ms |
94232 KB |
Output is correct |
6 |
Correct |
378 ms |
94112 KB |
Output is correct |
7 |
Correct |
422 ms |
94476 KB |
Output is correct |
8 |
Correct |
381 ms |
95308 KB |
Output is correct |
9 |
Correct |
398 ms |
60644 KB |
Output is correct |
10 |
Correct |
394 ms |
94400 KB |
Output is correct |
11 |
Correct |
393 ms |
94444 KB |
Output is correct |
12 |
Correct |
414 ms |
95460 KB |
Output is correct |
13 |
Correct |
435 ms |
95756 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
2 ms |
604 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
660 KB |
Output is correct |
18 |
Correct |
1 ms |
604 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
600 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
2 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
600 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
480 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
1 ms |
604 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
1 ms |
604 KB |
Output is correct |
39 |
Correct |
1 ms |
604 KB |
Output is correct |
40 |
Correct |
1 ms |
600 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
360 ms |
94288 KB |
Output is correct |
43 |
Correct |
361 ms |
60620 KB |
Output is correct |
44 |
Correct |
414 ms |
60752 KB |
Output is correct |
45 |
Correct |
343 ms |
60496 KB |
Output is correct |
46 |
Correct |
410 ms |
94232 KB |
Output is correct |
47 |
Correct |
378 ms |
94112 KB |
Output is correct |
48 |
Correct |
422 ms |
94476 KB |
Output is correct |
49 |
Correct |
381 ms |
95308 KB |
Output is correct |
50 |
Correct |
398 ms |
60644 KB |
Output is correct |
51 |
Correct |
394 ms |
94400 KB |
Output is correct |
52 |
Correct |
393 ms |
94444 KB |
Output is correct |
53 |
Correct |
414 ms |
95460 KB |
Output is correct |
54 |
Correct |
435 ms |
95756 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
431 ms |
91016 KB |
Output is correct |
57 |
Correct |
442 ms |
57428 KB |
Output is correct |
58 |
Correct |
413 ms |
91476 KB |
Output is correct |
59 |
Correct |
388 ms |
91764 KB |
Output is correct |
60 |
Correct |
365 ms |
57684 KB |
Output is correct |
61 |
Correct |
424 ms |
92360 KB |
Output is correct |
62 |
Correct |
407 ms |
91984 KB |
Output is correct |
63 |
Correct |
394 ms |
92244 KB |
Output is correct |
64 |
Correct |
385 ms |
92244 KB |
Output is correct |
65 |
Correct |
380 ms |
91216 KB |
Output is correct |
66 |
Correct |
374 ms |
91348 KB |
Output is correct |
67 |
Correct |
363 ms |
92160 KB |
Output is correct |
68 |
Correct |
362 ms |
76680 KB |
Output is correct |
69 |
Correct |
421 ms |
92360 KB |
Output is correct |
70 |
Correct |
336 ms |
57728 KB |
Output is correct |
71 |
Correct |
383 ms |
56660 KB |
Output is correct |
72 |
Correct |
354 ms |
68436 KB |
Output is correct |
73 |
Correct |
394 ms |
91728 KB |
Output is correct |
74 |
Correct |
377 ms |
91732 KB |
Output is correct |
75 |
Correct |
388 ms |
92036 KB |
Output is correct |
76 |
Correct |
389 ms |
92756 KB |
Output is correct |
77 |
Correct |
0 ms |
600 KB |
Output is correct |