/*#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(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 |
7424 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7384 KB |
Output is correct |
6 |
Correct |
4 ms |
7372 KB |
Output is correct |
7 |
Correct |
4 ms |
7372 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7372 KB |
Output is correct |
11 |
Correct |
5 ms |
7516 KB |
Output is correct |
12 |
Correct |
5 ms |
7588 KB |
Output is correct |
13 |
Correct |
5 ms |
7520 KB |
Output is correct |
14 |
Correct |
5 ms |
7520 KB |
Output is correct |
15 |
Correct |
5 ms |
7524 KB |
Output is correct |
16 |
Correct |
5 ms |
7500 KB |
Output is correct |
17 |
Correct |
6 ms |
7500 KB |
Output is correct |
18 |
Correct |
5 ms |
7528 KB |
Output is correct |
19 |
Correct |
5 ms |
7500 KB |
Output is correct |
20 |
Correct |
6 ms |
7500 KB |
Output is correct |
21 |
Correct |
5 ms |
7500 KB |
Output is correct |
22 |
Correct |
5 ms |
7572 KB |
Output is correct |
23 |
Correct |
7 ms |
7516 KB |
Output is correct |
24 |
Correct |
5 ms |
7500 KB |
Output is correct |
25 |
Correct |
6 ms |
7516 KB |
Output is correct |
26 |
Correct |
5 ms |
7500 KB |
Output is correct |
27 |
Correct |
5 ms |
7516 KB |
Output is correct |
28 |
Correct |
5 ms |
7524 KB |
Output is correct |
29 |
Correct |
5 ms |
7592 KB |
Output is correct |
30 |
Correct |
5 ms |
7592 KB |
Output is correct |
31 |
Correct |
5 ms |
7572 KB |
Output is correct |
32 |
Correct |
5 ms |
7500 KB |
Output is correct |
33 |
Correct |
7 ms |
7500 KB |
Output is correct |
34 |
Correct |
6 ms |
7568 KB |
Output is correct |
35 |
Correct |
5 ms |
7516 KB |
Output is correct |
36 |
Correct |
5 ms |
7584 KB |
Output is correct |
37 |
Correct |
5 ms |
7500 KB |
Output is correct |
38 |
Correct |
5 ms |
7500 KB |
Output is correct |
39 |
Correct |
6 ms |
7524 KB |
Output is correct |
40 |
Correct |
5 ms |
7500 KB |
Output is correct |
41 |
Runtime error |
236 ms |
524292 KB |
Execution killed with signal 9 |
42 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
484 ms |
71760 KB |
Output is correct |
2 |
Correct |
461 ms |
54852 KB |
Output is correct |
3 |
Correct |
499 ms |
55092 KB |
Output is correct |
4 |
Correct |
560 ms |
54760 KB |
Output is correct |
5 |
Correct |
579 ms |
71788 KB |
Output is correct |
6 |
Correct |
499 ms |
71620 KB |
Output is correct |
7 |
Correct |
486 ms |
71912 KB |
Output is correct |
8 |
Correct |
473 ms |
72388 KB |
Output is correct |
9 |
Correct |
468 ms |
54852 KB |
Output is correct |
10 |
Correct |
540 ms |
71868 KB |
Output is correct |
11 |
Correct |
478 ms |
71788 KB |
Output is correct |
12 |
Correct |
476 ms |
72388 KB |
Output is correct |
13 |
Correct |
548 ms |
72536 KB |
Output is correct |
14 |
Runtime error |
207 ms |
524292 KB |
Execution killed with signal 9 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
7424 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7384 KB |
Output is correct |
6 |
Correct |
4 ms |
7372 KB |
Output is correct |
7 |
Correct |
4 ms |
7372 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7372 KB |
Output is correct |
11 |
Correct |
5 ms |
7516 KB |
Output is correct |
12 |
Correct |
5 ms |
7588 KB |
Output is correct |
13 |
Correct |
5 ms |
7520 KB |
Output is correct |
14 |
Correct |
5 ms |
7520 KB |
Output is correct |
15 |
Correct |
5 ms |
7524 KB |
Output is correct |
16 |
Correct |
5 ms |
7500 KB |
Output is correct |
17 |
Correct |
6 ms |
7500 KB |
Output is correct |
18 |
Correct |
5 ms |
7528 KB |
Output is correct |
19 |
Correct |
5 ms |
7500 KB |
Output is correct |
20 |
Correct |
6 ms |
7500 KB |
Output is correct |
21 |
Correct |
5 ms |
7500 KB |
Output is correct |
22 |
Correct |
5 ms |
7572 KB |
Output is correct |
23 |
Correct |
7 ms |
7516 KB |
Output is correct |
24 |
Correct |
5 ms |
7500 KB |
Output is correct |
25 |
Correct |
6 ms |
7516 KB |
Output is correct |
26 |
Correct |
5 ms |
7500 KB |
Output is correct |
27 |
Correct |
5 ms |
7516 KB |
Output is correct |
28 |
Correct |
5 ms |
7524 KB |
Output is correct |
29 |
Correct |
5 ms |
7592 KB |
Output is correct |
30 |
Correct |
5 ms |
7592 KB |
Output is correct |
31 |
Correct |
5 ms |
7572 KB |
Output is correct |
32 |
Correct |
5 ms |
7500 KB |
Output is correct |
33 |
Correct |
7 ms |
7500 KB |
Output is correct |
34 |
Correct |
6 ms |
7568 KB |
Output is correct |
35 |
Correct |
5 ms |
7516 KB |
Output is correct |
36 |
Correct |
5 ms |
7584 KB |
Output is correct |
37 |
Correct |
5 ms |
7500 KB |
Output is correct |
38 |
Correct |
5 ms |
7500 KB |
Output is correct |
39 |
Correct |
6 ms |
7524 KB |
Output is correct |
40 |
Correct |
5 ms |
7500 KB |
Output is correct |
41 |
Runtime error |
236 ms |
524292 KB |
Execution killed with signal 9 |
42 |
Halted |
0 ms |
0 KB |
- |