#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using lint = long long;
using intp = pair<int,int>;
using vint = vector<int>;
const int MAX_N=300010;
struct Obj
{
lint t,v;
};
struct Seg
{
lint tl,tr,tc,vc;
void setv(lint nl,lint nr)
{
tl=nl;
tr=nr-1;
tc=nl+1;
vc=0;
}
Obj pass(Obj o) const
{
Obj ret;
ret.t=tc+max(0LL,min(o.t-tl,tr-tl));
ret.v=o.v+vc+max(0LL,o.t-tr);
return ret;
}
};
int n,q;
Seg seg[2][MAX_N<<2];
void merge_(Seg &p,const Seg &l,const Seg &r)
{
if(l.tc>=r.tr)
p.tl=p.tr=l.tl;
else if(l.tc+l.tr-l.tl<=r.tl)
p.tl=p.tr=l.tr;
else
{
p.tl=max(l.tl,r.tl-l.tc+l.tl);
p.tr=min(l.tr,r.tr-l.tc+l.tl);
}
p.tc=r.pass(l.pass({p.tl,0})).t;
p.vc=r.pass(l.pass({p.tl,0})).v;
}
void update_(int i,int t,int s,int e,int x,lint nl,lint nr)
{
if(s>x || e<=x)
return;
if(s==x && x+1==e)
{
seg[t][i].setv(nl,nr);
return;
}
update_(i<<1,t,s,(s+e)>>1,x,nl,nr);
update_(i<<1|1,t,(s+e)>>1,e,x,nl,nr);
merge_(seg[t][i],seg[t][i<<1],seg[t][i<<1|1]);
}
Obj find_(int i,int t,int s,int e,int l,int r,Obj v)
{
if(s>=r || e<=l)
return v;
if(l<=s && e<=r)
return seg[t][i].pass(v);
v=find_(i<<1,t,s,(s+e)>>1,l,r,v);
return find_(i<<1|1,t,(s+e)>>1,e,l,r,v);
}
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> q;
for(int i=1;i<n;i++)
{
lint l,r;
cin >> l >> r;
update_(1,0,0,n-1,i-1,l,r);
update_(1,1,0,n-1,n-1-i,l,r);
}
while(q--)
{
int t,x,sp,ep;
lint nl,nr,st,et;
cin >> t;
if(t==1)
{
cin >> x >> nl >> nr;
update_(1,0,0,n-1,x-1,nl,nr);
update_(1,1,0,n-1,n-1-x,nl,nr);
}
else
{
cin >> sp >> st >> ep >> et;
if(sp==ep)
cout << max(0LL,st-et) << '\n';
else if(sp<ep)
{
Obj v=find_(1,0,0,n-1,sp-1,ep-1,{st,0});
cout << v.v+max(0LL,v.t-et) << '\n';
}
else
{
Obj v=find_(1,1,0,n-1,n-sp,n-ep,{st,0});
cout << v.v+max(0LL,v.t-et) << '\n';
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
644 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
480 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 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 |
604 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 |
644 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 |
480 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
476 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 |
604 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 |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
616 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
448 ms |
83024 KB |
Output is correct |
2 |
Correct |
422 ms |
52560 KB |
Output is correct |
3 |
Correct |
403 ms |
52816 KB |
Output is correct |
4 |
Correct |
421 ms |
52560 KB |
Output is correct |
5 |
Correct |
445 ms |
85896 KB |
Output is correct |
6 |
Correct |
433 ms |
85584 KB |
Output is correct |
7 |
Correct |
451 ms |
85856 KB |
Output is correct |
8 |
Correct |
502 ms |
86304 KB |
Output is correct |
9 |
Correct |
479 ms |
52820 KB |
Output is correct |
10 |
Correct |
461 ms |
85840 KB |
Output is correct |
11 |
Correct |
515 ms |
85832 KB |
Output is correct |
12 |
Correct |
513 ms |
86172 KB |
Output is correct |
13 |
Correct |
558 ms |
86376 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
644 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
480 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 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 |
604 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 |
644 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 |
480 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
1 ms |
476 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 |
604 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 |
600 KB |
Output is correct |
39 |
Correct |
1 ms |
616 KB |
Output is correct |
40 |
Correct |
1 ms |
604 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
448 ms |
83024 KB |
Output is correct |
43 |
Correct |
422 ms |
52560 KB |
Output is correct |
44 |
Correct |
403 ms |
52816 KB |
Output is correct |
45 |
Correct |
421 ms |
52560 KB |
Output is correct |
46 |
Correct |
445 ms |
85896 KB |
Output is correct |
47 |
Correct |
433 ms |
85584 KB |
Output is correct |
48 |
Correct |
451 ms |
85856 KB |
Output is correct |
49 |
Correct |
502 ms |
86304 KB |
Output is correct |
50 |
Correct |
479 ms |
52820 KB |
Output is correct |
51 |
Correct |
461 ms |
85840 KB |
Output is correct |
52 |
Correct |
515 ms |
85832 KB |
Output is correct |
53 |
Correct |
513 ms |
86172 KB |
Output is correct |
54 |
Correct |
558 ms |
86376 KB |
Output is correct |
55 |
Correct |
1 ms |
344 KB |
Output is correct |
56 |
Correct |
514 ms |
82672 KB |
Output is correct |
57 |
Correct |
509 ms |
49532 KB |
Output is correct |
58 |
Correct |
528 ms |
82840 KB |
Output is correct |
59 |
Correct |
571 ms |
82936 KB |
Output is correct |
60 |
Correct |
499 ms |
49636 KB |
Output is correct |
61 |
Correct |
536 ms |
83036 KB |
Output is correct |
62 |
Correct |
495 ms |
82996 KB |
Output is correct |
63 |
Correct |
479 ms |
83024 KB |
Output is correct |
64 |
Correct |
547 ms |
83040 KB |
Output is correct |
65 |
Correct |
527 ms |
82772 KB |
Output is correct |
66 |
Correct |
495 ms |
82772 KB |
Output is correct |
67 |
Correct |
502 ms |
83088 KB |
Output is correct |
68 |
Correct |
481 ms |
68516 KB |
Output is correct |
69 |
Correct |
523 ms |
83104 KB |
Output is correct |
70 |
Correct |
465 ms |
49492 KB |
Output is correct |
71 |
Correct |
489 ms |
48720 KB |
Output is correct |
72 |
Correct |
493 ms |
60252 KB |
Output is correct |
73 |
Correct |
507 ms |
82524 KB |
Output is correct |
74 |
Correct |
494 ms |
82512 KB |
Output is correct |
75 |
Correct |
538 ms |
82768 KB |
Output is correct |
76 |
Correct |
495 ms |
83168 KB |
Output is correct |
77 |
Correct |
1 ms |
348 KB |
Output is correct |