/*#pragma GCC optimize("Ofast,unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")*/
/*#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using point=complex<double>;
#define F first
#define S second
//#define X real()
//#define Y imag()
#define pb push_back
#define mp make_pair
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define kill(x) cout << x << '\n';exit(0)
#define killshayan kill("done!")
#define killmashtali kill("Hello, World!")
const int N=3e5+10,LN=19,M=3e2+10,SQ=256,BS=737,inf=1e9;
const ll INF=1e18;
const double pi=acos(-1);
const ld ep=1e-7;
const int MH=1000696969,MD=998244353,MOD=1000000007;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type,greater<pii>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
ll ans=1;
while (y != 0) {
if (y & 1) ans = ans * x % mod;
y >>= 1;
x = x * x % mod;
}
return ans;
}
struct node{
ll mt,lx,rx,mn;
ll get(ll x){
if(x<=mt) return mn;
return x-mt+mn;
}
ll getx(ll x){
return min(rx,max(lx,x));
}
node operator+(node k){
node ans={lx<rx?min(mt,max(lx,k.mt)):mt,k.getx(lx),k.getx(rx),mn+k.get(lx)};
return ans;
}
} f[N*4];
ll n,q,a[N],b[N],c[N],d[N],ans[N],t[N];
vector<ll> qu[N];
void build(ll v, ll l, ll r){
if(l==r) return;
if(r-l==1){
f[v].mt=f[v].rx=b[l];
f[v].lx=a[l];
f[v].mn=0;
return;
}
ll m=(l+r)>>1;
build(lc,l,m);
build(rc,m,r);
f[v]=f[lc]+f[rc];
}
void upd(ll v, ll l, ll r, ll p){
if(r-l==1){
f[v].mt=f[v].rx=b[l];
f[v].lx=a[l];
f[v].mn=0;
return;
}
ll m=(l+r)>>1;
if(p<m) upd(lc,l,m,p);
else upd(rc,m,r,p);
f[v]=f[lc]+f[rc];
}
node get(ll v, ll l, ll r, ll tl, ll tr){
if(tl>=tr || l>=tr || tl>=r) return f[0];
if(l>=tl && r<=tr) return f[v];
ll m=(l+r)>>1;
return get(lc,l,m,tl,tr)+get(rc,m,r,tl,tr);
}
int main(){
fast_io;
f[0]={INF,-INF,INF,0};
cin >> n >> q;
for(ll i=1; i<n; i++){
cin >> c[i] >> d[i];
a[i]=c[i]-i;
d[i]--;
b[i]=d[i]-i;
}
build(1,1,n);
for(ll i=1; i<=q; i++){
cin >> t[i];
if(t[i]==1){
ll j,l,r;
cin >> j >> l >> r;
r--;
qu[i]={j,l,r};
a[j]=l-j;
b[j]=r-j;
upd(1,1,n,j);
}else{
ll s,st,e,et;
cin >> s >> st >> e >> et;
qu[i]={s,st,e,et};
if(s<=e){
et-=e;
st-=s;
if(s==e) ans[i]=max(0ll,st-et);
else{
node k=get(1,1,n,s,e);
ans[i]=k.get(st)+max(0ll,k.getx(st)-et);
}
}
}
}
for(ll i=1; i<n; i++){
a[i]=c[n-i]-i;
b[i]=d[n-i]-i;
}
for(ll i=1; i<=q; i++){
if(t[i]==1){
qu[i][0]=n-qu[i][0];
}else{
qu[i][0]=n+1-qu[i][0];
qu[i][2]=n+1-qu[i][2];
}
}
build(1,1,n);
for(ll i=1; i<=q; i++){
if(t[i]==1){
ll j=qu[i][0],l=qu[i][1],r=qu[i][2];
a[j]=l-j;
b[j]=r-j;
upd(1,1,n,j);
}else{
ll s=qu[i][0],st=qu[i][1],e=qu[i][2],et=qu[i][3];
if(s<e){
et-=e;
st-=s;
node k=get(1,1,n,s,e);
ans[i]=k.get(st)+max(0ll,k.getx(st)-et);
}
}
}
for(ll i=1; i<=q; i++) if(t[i]==2) cout << ans[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7420 KB |
Output is correct |
7 |
Correct |
4 ms |
7372 KB |
Output is correct |
8 |
Correct |
3 ms |
7372 KB |
Output is correct |
9 |
Correct |
4 ms |
7372 KB |
Output is correct |
10 |
Correct |
4 ms |
7300 KB |
Output is correct |
11 |
Correct |
5 ms |
7500 KB |
Output is correct |
12 |
Correct |
5 ms |
7500 KB |
Output is correct |
13 |
Correct |
4 ms |
7500 KB |
Output is correct |
14 |
Correct |
5 ms |
7500 KB |
Output is correct |
15 |
Correct |
5 ms |
7500 KB |
Output is correct |
16 |
Correct |
5 ms |
7500 KB |
Output is correct |
17 |
Correct |
5 ms |
7500 KB |
Output is correct |
18 |
Correct |
5 ms |
7492 KB |
Output is correct |
19 |
Correct |
4 ms |
7500 KB |
Output is correct |
20 |
Correct |
5 ms |
7500 KB |
Output is correct |
21 |
Correct |
5 ms |
7500 KB |
Output is correct |
22 |
Correct |
4 ms |
7500 KB |
Output is correct |
23 |
Correct |
5 ms |
7500 KB |
Output is correct |
24 |
Correct |
5 ms |
7552 KB |
Output is correct |
25 |
Correct |
5 ms |
7512 KB |
Output is correct |
26 |
Correct |
5 ms |
7500 KB |
Output is correct |
27 |
Correct |
5 ms |
7500 KB |
Output is correct |
28 |
Correct |
5 ms |
7500 KB |
Output is correct |
29 |
Correct |
5 ms |
7564 KB |
Output is correct |
30 |
Correct |
7 ms |
7500 KB |
Output is correct |
31 |
Correct |
5 ms |
7500 KB |
Output is correct |
32 |
Correct |
5 ms |
7500 KB |
Output is correct |
33 |
Correct |
5 ms |
7500 KB |
Output is correct |
34 |
Correct |
5 ms |
7500 KB |
Output is correct |
35 |
Correct |
5 ms |
7572 KB |
Output is correct |
36 |
Correct |
5 ms |
7544 KB |
Output is correct |
37 |
Correct |
7 ms |
7500 KB |
Output is correct |
38 |
Correct |
5 ms |
7500 KB |
Output is correct |
39 |
Correct |
5 ms |
7500 KB |
Output is correct |
40 |
Correct |
5 ms |
7500 KB |
Output is correct |
41 |
Correct |
4 ms |
7372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
539 ms |
71700 KB |
Output is correct |
2 |
Correct |
481 ms |
54876 KB |
Output is correct |
3 |
Correct |
476 ms |
55016 KB |
Output is correct |
4 |
Correct |
472 ms |
54596 KB |
Output is correct |
5 |
Correct |
523 ms |
71760 KB |
Output is correct |
6 |
Correct |
490 ms |
71516 KB |
Output is correct |
7 |
Correct |
550 ms |
71900 KB |
Output is correct |
8 |
Correct |
508 ms |
72388 KB |
Output is correct |
9 |
Correct |
474 ms |
54768 KB |
Output is correct |
10 |
Correct |
502 ms |
71888 KB |
Output is correct |
11 |
Correct |
513 ms |
71852 KB |
Output is correct |
12 |
Correct |
506 ms |
72456 KB |
Output is correct |
13 |
Correct |
507 ms |
72544 KB |
Output is correct |
14 |
Correct |
4 ms |
7372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Correct |
4 ms |
7372 KB |
Output is correct |
6 |
Correct |
4 ms |
7420 KB |
Output is correct |
7 |
Correct |
4 ms |
7372 KB |
Output is correct |
8 |
Correct |
3 ms |
7372 KB |
Output is correct |
9 |
Correct |
4 ms |
7372 KB |
Output is correct |
10 |
Correct |
4 ms |
7300 KB |
Output is correct |
11 |
Correct |
5 ms |
7500 KB |
Output is correct |
12 |
Correct |
5 ms |
7500 KB |
Output is correct |
13 |
Correct |
4 ms |
7500 KB |
Output is correct |
14 |
Correct |
5 ms |
7500 KB |
Output is correct |
15 |
Correct |
5 ms |
7500 KB |
Output is correct |
16 |
Correct |
5 ms |
7500 KB |
Output is correct |
17 |
Correct |
5 ms |
7500 KB |
Output is correct |
18 |
Correct |
5 ms |
7492 KB |
Output is correct |
19 |
Correct |
4 ms |
7500 KB |
Output is correct |
20 |
Correct |
5 ms |
7500 KB |
Output is correct |
21 |
Correct |
5 ms |
7500 KB |
Output is correct |
22 |
Correct |
4 ms |
7500 KB |
Output is correct |
23 |
Correct |
5 ms |
7500 KB |
Output is correct |
24 |
Correct |
5 ms |
7552 KB |
Output is correct |
25 |
Correct |
5 ms |
7512 KB |
Output is correct |
26 |
Correct |
5 ms |
7500 KB |
Output is correct |
27 |
Correct |
5 ms |
7500 KB |
Output is correct |
28 |
Correct |
5 ms |
7500 KB |
Output is correct |
29 |
Correct |
5 ms |
7564 KB |
Output is correct |
30 |
Correct |
7 ms |
7500 KB |
Output is correct |
31 |
Correct |
5 ms |
7500 KB |
Output is correct |
32 |
Correct |
5 ms |
7500 KB |
Output is correct |
33 |
Correct |
5 ms |
7500 KB |
Output is correct |
34 |
Correct |
5 ms |
7500 KB |
Output is correct |
35 |
Correct |
5 ms |
7572 KB |
Output is correct |
36 |
Correct |
5 ms |
7544 KB |
Output is correct |
37 |
Correct |
7 ms |
7500 KB |
Output is correct |
38 |
Correct |
5 ms |
7500 KB |
Output is correct |
39 |
Correct |
5 ms |
7500 KB |
Output is correct |
40 |
Correct |
5 ms |
7500 KB |
Output is correct |
41 |
Correct |
4 ms |
7372 KB |
Output is correct |
42 |
Correct |
539 ms |
71700 KB |
Output is correct |
43 |
Correct |
481 ms |
54876 KB |
Output is correct |
44 |
Correct |
476 ms |
55016 KB |
Output is correct |
45 |
Correct |
472 ms |
54596 KB |
Output is correct |
46 |
Correct |
523 ms |
71760 KB |
Output is correct |
47 |
Correct |
490 ms |
71516 KB |
Output is correct |
48 |
Correct |
550 ms |
71900 KB |
Output is correct |
49 |
Correct |
508 ms |
72388 KB |
Output is correct |
50 |
Correct |
474 ms |
54768 KB |
Output is correct |
51 |
Correct |
502 ms |
71888 KB |
Output is correct |
52 |
Correct |
513 ms |
71852 KB |
Output is correct |
53 |
Correct |
506 ms |
72456 KB |
Output is correct |
54 |
Correct |
507 ms |
72544 KB |
Output is correct |
55 |
Correct |
4 ms |
7372 KB |
Output is correct |
56 |
Correct |
516 ms |
69612 KB |
Output is correct |
57 |
Correct |
496 ms |
52672 KB |
Output is correct |
58 |
Correct |
512 ms |
70088 KB |
Output is correct |
59 |
Correct |
521 ms |
70108 KB |
Output is correct |
60 |
Correct |
493 ms |
52844 KB |
Output is correct |
61 |
Correct |
536 ms |
70392 KB |
Output is correct |
62 |
Correct |
530 ms |
70260 KB |
Output is correct |
63 |
Correct |
519 ms |
70228 KB |
Output is correct |
64 |
Correct |
513 ms |
70244 KB |
Output is correct |
65 |
Correct |
521 ms |
69788 KB |
Output is correct |
66 |
Correct |
517 ms |
69932 KB |
Output is correct |
67 |
Correct |
520 ms |
70312 KB |
Output is correct |
68 |
Correct |
500 ms |
62768 KB |
Output is correct |
69 |
Correct |
508 ms |
70660 KB |
Output is correct |
70 |
Correct |
489 ms |
53028 KB |
Output is correct |
71 |
Correct |
505 ms |
52752 KB |
Output is correct |
72 |
Correct |
514 ms |
58576 KB |
Output is correct |
73 |
Correct |
548 ms |
70352 KB |
Output is correct |
74 |
Correct |
521 ms |
70340 KB |
Output is correct |
75 |
Correct |
502 ms |
70512 KB |
Output is correct |
76 |
Correct |
503 ms |
70616 KB |
Output is correct |
77 |
Correct |
4 ms |
7372 KB |
Output is correct |