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>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=3e5+7;
ll A[LIM], B[LIM];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, q;
cin >> n >> q;
rep(i, n-1) {
cin >> A[i] >> B[i];
--B[i];
}
while(q--) {
ll t, a, b, c, d;
cin >> t;
if(t==1) {
cin >> a >> b >> c; --a;
A[a]=b;
B[a]=c-1;
continue;
}
cin >> a >> b >> c >> d; --a; --c;
ll ans=0;
while(a<c) {
if(b<=A[a]) {
b=A[a]+1;
++a;
continue;
}
if(b>B[a]) {
ans+=b-B[a];
b=B[a]+1;
++a;
continue;
}
++b;
++a;
}
while(a>c) {
--a;
if(b<=A[a]) {
b=A[a]+1;
continue;
}
if(b>B[a]) {
ans+=b-B[a];
b=B[a]+1;
continue;
}
++b;
}
if(b>d) ans+=b-d;
cout << ans << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |