#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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
4 ms |
364 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
364 KB |
Output is correct |
16 |
Correct |
3 ms |
364 KB |
Output is correct |
17 |
Correct |
3 ms |
364 KB |
Output is correct |
18 |
Correct |
3 ms |
364 KB |
Output is correct |
19 |
Correct |
3 ms |
364 KB |
Output is correct |
20 |
Correct |
3 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
3 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
2 ms |
364 KB |
Output is correct |
29 |
Correct |
3 ms |
492 KB |
Output is correct |
30 |
Correct |
3 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
2 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
3 ms |
364 KB |
Output is correct |
36 |
Correct |
2 ms |
364 KB |
Output is correct |
37 |
Correct |
3 ms |
364 KB |
Output is correct |
38 |
Correct |
3 ms |
364 KB |
Output is correct |
39 |
Correct |
2 ms |
364 KB |
Output is correct |
40 |
Correct |
4 ms |
364 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
7916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
4 ms |
364 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
364 KB |
Output is correct |
16 |
Correct |
3 ms |
364 KB |
Output is correct |
17 |
Correct |
3 ms |
364 KB |
Output is correct |
18 |
Correct |
3 ms |
364 KB |
Output is correct |
19 |
Correct |
3 ms |
364 KB |
Output is correct |
20 |
Correct |
3 ms |
364 KB |
Output is correct |
21 |
Correct |
2 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
364 KB |
Output is correct |
25 |
Correct |
2 ms |
364 KB |
Output is correct |
26 |
Correct |
3 ms |
364 KB |
Output is correct |
27 |
Correct |
2 ms |
364 KB |
Output is correct |
28 |
Correct |
2 ms |
364 KB |
Output is correct |
29 |
Correct |
3 ms |
492 KB |
Output is correct |
30 |
Correct |
3 ms |
364 KB |
Output is correct |
31 |
Correct |
3 ms |
364 KB |
Output is correct |
32 |
Correct |
2 ms |
364 KB |
Output is correct |
33 |
Correct |
2 ms |
364 KB |
Output is correct |
34 |
Correct |
3 ms |
364 KB |
Output is correct |
35 |
Correct |
3 ms |
364 KB |
Output is correct |
36 |
Correct |
2 ms |
364 KB |
Output is correct |
37 |
Correct |
3 ms |
364 KB |
Output is correct |
38 |
Correct |
3 ms |
364 KB |
Output is correct |
39 |
Correct |
2 ms |
364 KB |
Output is correct |
40 |
Correct |
4 ms |
364 KB |
Output is correct |
41 |
Correct |
1 ms |
364 KB |
Output is correct |
42 |
Incorrect |
65 ms |
7916 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |