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;
const int MAXN = (int)1e3 + 3;
const ll infint = (int)1e9 + 3;
const int MOD = (int)1e9 + 7;
const ll inf = (ll)1e18 + 3;
int n, q, l[MAXN], r[MAXN];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n - 1; i++)
{
cin >> l[i] >> r[i];
r[i]--;
}
for (int i = 0; i < q; i++)
{
int type;
cin >> type;
if(type == 1)
{
int id, x, y;
cin >> id >> x >> y;
l[id] = x, r[id] = y - 1;
}
else
{
int A, tx, B, ty;
cin >> A >> tx >> B >> ty;
ll ans = 0;
if(A < B)
{
while(A ^ B)
{
if(tx > r[A])
ans += tx - r[A], tx = r[A];
if(tx < l[A])
tx = l[A];
tx++, A++;
}
if(tx > ty)
ans += tx - ty;
}
else
{
while(A ^ B)
{
if(tx > r[A - 1])
ans += tx - r[A - 1], tx = r[A - 1];
if(tx < l[A - 1])
tx = l[A - 1];
tx++, A--;
}
if(tx > ty)
ans += tx - ty;
}
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... |