This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Nmax=300010;
int N, Q, L[Nmax], R[Nmax];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N>>Q;
for(int i=1; i<N; i++) cin>>L[i]>>R[i];
while(Q--) {
int op; cin>>op;
if(op==1) {
int k, l, r; cin>>k>>l>>r;
L[k]=l, R[k]=r;
}
else {
int s, x, e, y, ans=0;
cin>>s>>x>>e>>y;
if(s<e) {
for(int i=s; i<e; i++) {
if(x<=L[i]) x=L[i]+1;
else if(x<R[i]) x++;
else ans+=x-(R[i]-1), x=R[i];
}
ans+=max(0ll, x-y);
}
else {
for(int i=s-1; i>=e; i--) {
if(x<=L[i]) x=L[i]+1;
else if(x<R[i]) x++;
else ans+=x-(R[i]-1), x=R[i];
}
ans+=max(0ll, x-y);
}
cout<<ans<<"\n";
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |