#include <bits/stdc++.h>
#define int long long
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
const int T = 1'000'000'000;
int N, Q, L[2005], R[2005];
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N >> Q;
for (int i = 1; i < N; i++)
{
cin >> L[i] >> R[i];
R[i]--;
}
for (int i = 1; i <= Q; i++)
{
int T, A, B, C, D;
cin >> T;
if (T == 1)
{
cin >> A >> B >> C;
L[A] = B;
R[A] = C - 1;
}
else
{
cin >> A >> B >> C >> D;
if (A < C)
{
ll ans = 0, t = B;
for (int i = A; i < C; i++)
{
if (t < L[i])
t = L[i];
else if (t > R[i])
ans += t - R[i], t = R[i];
t++;
}
ans += max(0LL, t - D);
cout << ans << '\n';
}
else if (C < A)
{
ll ans = 0, t = B;
for (int i = A - 1; i >= C; i--)
{
if(t < L[i])
t = L[i];
else if(t > R[i])
ans += t - R[i], t = R[i];
t++;
}
ans += max(0LL, t - D);
cout << ans << '\n';
}
else
cout << max(0LL, B - D) << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
324 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
380 KB |
Output is correct |
25 |
Correct |
2 ms |
392 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
336 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
2 ms |
340 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
2 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
340 KB |
Output is correct |
39 |
Correct |
2 ms |
340 KB |
Output is correct |
40 |
Correct |
2 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
2 ms |
340 KB |
Output is correct |
13 |
Correct |
2 ms |
324 KB |
Output is correct |
14 |
Correct |
2 ms |
344 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
380 KB |
Output is correct |
25 |
Correct |
2 ms |
392 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
336 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
336 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
336 KB |
Output is correct |
33 |
Correct |
2 ms |
340 KB |
Output is correct |
34 |
Correct |
2 ms |
340 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
2 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
340 KB |
Output is correct |
39 |
Correct |
2 ms |
340 KB |
Output is correct |
40 |
Correct |
2 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
324 KB |
Output is correct |
42 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 11 |
43 |
Halted |
0 ms |
0 KB |
- |