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;
int solve(vector<int> l, vector<int> r) {
int n = l.size();
int t = -1;
int res = 0;
for (int i = 0; i < n; ++i) {
if (t > r[i]) {
res += t - r[i];
t = r[i];
}
if (t < l[i]) {
t = l[i];
}
++t;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> l(n), r(n);
for (int i = 0; i < n - 1; ++i) {
cin >> l[i] >> r[i];
--r[i];
}
while (q--) {
int t;
cin >> t;
if (t == 1) {
int p, s, e;
cin >> p >> s >> e;
--p, --e;
l[p] = s, r[p] = e;
}
if (t == 2) {
int a, b, c, d;
cin >> a >> b >> c >> d;
--a, --c;
if (a == c) {
cout << max(0, b - d) << "\n";
} else {
vector<int> cl, cr;
cl.push_back(b - 1);
cr.push_back(b - 1);
if (a < c) {
for (int i = a; i < c; ++i) {
cl.push_back(l[i]);
cr.push_back(r[i]);
}
} else {
for (int i = a - 1; i >= c; --i) {
cl.push_back(l[i]);
cr.push_back(r[i]);
}
}
cl.push_back(d);
cr.push_back(d);
cout << solve(cl, cr) << "\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... |