이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |