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;
using ll = long long;
const int maxn = 3e5 + 69;
int n, q;
array<int, 2> r[maxn];
void gate(int &x, ll &ans, int l, int r) {
if(x > r) {
ans += x-r;
x = r;
}
if(x < l) {
x = l;
}
}
void naive() {
for(int t, a, b, c, d; q--;) {
cin >> t >> a >> b >> c;
if(t == 1) {
--a;
r[a] = {b, c-1};
} else {
cin >> d;
a--, c--;
ll ans = 0;
if(a <= c) {
b -= a;
d -= c;
for(int i = a; i < c; i++) {
gate(b, ans, r[i][0]-i, r[i][1]-i);
// cout << i << " " << b << " " << ans << endl;
}
} else {
b += a;
d += c;
//cout << b << " " << a << endl;
for(int i = a-1; i >= c; i--) {
//cout << b << " with " << r[i][0]+i << " " << r[i][1]+i << endl;
gate(b, ans, r[i][0]+i+1, r[i][1]+i+1);
//cout << i << " " << b << " " << ans << endl;
}
}
ans += max(0, b-d);
cout << ans << '\n';
}
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> q;
for(int i = 0; i+1 < n; i++) {
cin >> r[i][0] >> r[i][1];
r[i][1]--;
//r[i][0] -= i, r[i][1] -= i;
}
if(max(n, q) <= 1000) naive();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |