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;
#define f first
#define s second
typedef long long ll;
const int N = 2005;
int n, q, t, p, s, e, a, b, c , d, l[N], r[N];
int main()
{
cin >> n >> q;
for(int i=0; i<n-1; i++) cin >> l[i] >> r[i];
while(q--)
{
cin >> t;
if(t == 1)
{
cin >> p >> s >> e;
l[p-1] = s, r[p-1] = e;
}
else
{
cin >> a >> b >> c >> d;
ll ans = 0;
if(a < c)
{
for(int i=a-1; i<c-1; i++)
{
b = max(b, l[i]);
if(b >= l[i] && b < r[i]) b++;
else ans += b-r[i]+1, b = r[i];
}
}
else
{
for(int i=a-2; i>=c-1; i--)
{
//cout << b << " " << ans << endl;
b = max(b, l[i]);
if(b >= l[i] && b < r[i]) b++;
else ans += b-r[i]+1, b = r[i];
}
//cout << "--------------------------\n";
}
cout << ans + max(0, b-d) << endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |