This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*****************/
/* [o] Subtask 1 */
/* [ ] Subtask 2 */
/* [ ] Subtask 3 */
/*****************/
#include <bits/stdc++.h>
using namespace std;
#define Foxyy cin.tie(0); cout.sync_with_stdio(0);
#define ll long long
struct Solver {
int n;
int q;
vector<int>& l;
vector<int>& r;
void modify(int p, int s, int e) {
l[p] = s;
r[p] = e;
}
void query(int a, int b, int c, int d) {
int t = b;
ll ans = 0;
if (c >= a) {
for (int i = a; i < c; i++) {
t = max(t, l[i]);
t++;
if (t > r[i]) {
ans += t-r[i];
t = r[i];
}
}
ans += max(t - d, 0);
cout << ans << '\n';
} else {
for (int i = a-1; i >= c; i--) {
t = max(t, l[i]);
t++;
if (t > r[i]) {
ans += t-r[i];
t = r[i];
}
}
ans += max(t - d, 0);
cout << ans << '\n';
}
}
void solve() {
while (q--) {
int t;
cin >> t;
if (t == 1) {
int p, s, e;
cin >> p >> s >> e;
p--;
modify(p, s, e);
} else {
int a, b, c, d;
cin >> a >> b >> c >> d;
a--, c--;
query(a, b, c, d);
}
}
}
};
signed main() {
Foxyy
int T = 1;
// cin >> T;
while (T--) {
int n, q;
cin >> n >> q;
vector<int> l(n-1), r(n-1);
for (int i = 0; i < n-1; i++) {
cin >> l[i] >> r[i];
}
Solver solver{n, q, l, r};
solver.solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |