#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(), v.end()
#define pb push_back
const int L = 70;
int arr[250005], lft[250005], tmp[250005];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> arr[i];
auto update = [&](int i) {
lft[i] = 0;
ll cur = 0;
for (int j = i; j > 0 && j > i - L; --j) {
cur += arr[j];
if (cur > max(arr[j - 1], arr[i + 1])) {
lft[i] = j;
break;
}
}
};
for (int i = 1; i <= n; ++i)
update(i);
int q;
cin >> q;
for (int i = 1; i <= q; ++i) {
int x, y, a, b;
cin >> x >> y >> a >> b;
arr[x] = y;
for (int j = max(1, x - 1); j <= n && j <= x + L; ++j)
update(j);
int ans = 1;
ll cur = 0;
for (int j = a + 1; j < b && j <= a + L; ++j) {
tmp[j] = lft[j];
cur += arr[j];
if (cur > arr[j + 1]) lft[j] = max(lft[j], a + 1);
}
tmp[b] = lft[b], lft[b] = 0, cur = 0;
for (int j = b; j > a && j > b - L; --j) {
cur += arr[j];
if (j == a + 1 || cur > arr[j - 1]) {
lft[b] = j;
break;
}
}
pii one = pll(a - 1, -1);
pii two = pll(a, 0);
for (int j = a + 1; j <= b; ++j) {
if (lft[j] - 1 > one.X) one.X = j, one.Y += 2;
if (lft[j] - 1 > two.X) two.X = j, two.Y += 2;
if (j == b) ans = max({ans, one.Y, two.Y});
else ans = max({ans, one.Y + 1, two.Y + 1});
}
for (int j = a + 1; j <= b && j <= a + L; ++j)
lft[j] = tmp[j];
lft[b] = tmp[b];
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
21 ms |
2004 KB |
Output is correct |
42 |
Correct |
22 ms |
2264 KB |
Output is correct |
43 |
Correct |
22 ms |
2312 KB |
Output is correct |
44 |
Correct |
18 ms |
1668 KB |
Output is correct |
45 |
Correct |
25 ms |
2336 KB |
Output is correct |
46 |
Correct |
30 ms |
2260 KB |
Output is correct |
47 |
Correct |
27 ms |
1748 KB |
Output is correct |
48 |
Correct |
28 ms |
2260 KB |
Output is correct |
49 |
Correct |
29 ms |
2248 KB |
Output is correct |
50 |
Correct |
29 ms |
2288 KB |
Output is correct |
51 |
Correct |
29 ms |
2252 KB |
Output is correct |
52 |
Correct |
21 ms |
1856 KB |
Output is correct |
53 |
Correct |
29 ms |
2348 KB |
Output is correct |
54 |
Correct |
27 ms |
2260 KB |
Output is correct |
55 |
Correct |
22 ms |
2260 KB |
Output is correct |
56 |
Correct |
26 ms |
2360 KB |
Output is correct |
57 |
Correct |
21 ms |
2252 KB |
Output is correct |
58 |
Correct |
26 ms |
2252 KB |
Output is correct |
59 |
Correct |
24 ms |
2252 KB |
Output is correct |
60 |
Correct |
26 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
78 ms |
2632 KB |
Output is correct |
3 |
Correct |
106 ms |
3424 KB |
Output is correct |
4 |
Correct |
308 ms |
3012 KB |
Output is correct |
5 |
Correct |
1465 ms |
3556 KB |
Output is correct |
6 |
Execution timed out |
4065 ms |
4104 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
224 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
72 ms |
3128 KB |
Output is correct |
4 |
Correct |
114 ms |
3440 KB |
Output is correct |
5 |
Correct |
1481 ms |
3452 KB |
Output is correct |
6 |
Execution timed out |
4070 ms |
3764 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
21 ms |
2004 KB |
Output is correct |
42 |
Correct |
22 ms |
2264 KB |
Output is correct |
43 |
Correct |
22 ms |
2312 KB |
Output is correct |
44 |
Correct |
18 ms |
1668 KB |
Output is correct |
45 |
Correct |
25 ms |
2336 KB |
Output is correct |
46 |
Correct |
30 ms |
2260 KB |
Output is correct |
47 |
Correct |
27 ms |
1748 KB |
Output is correct |
48 |
Correct |
28 ms |
2260 KB |
Output is correct |
49 |
Correct |
29 ms |
2248 KB |
Output is correct |
50 |
Correct |
29 ms |
2288 KB |
Output is correct |
51 |
Correct |
29 ms |
2252 KB |
Output is correct |
52 |
Correct |
21 ms |
1856 KB |
Output is correct |
53 |
Correct |
29 ms |
2348 KB |
Output is correct |
54 |
Correct |
27 ms |
2260 KB |
Output is correct |
55 |
Correct |
22 ms |
2260 KB |
Output is correct |
56 |
Correct |
26 ms |
2360 KB |
Output is correct |
57 |
Correct |
21 ms |
2252 KB |
Output is correct |
58 |
Correct |
26 ms |
2252 KB |
Output is correct |
59 |
Correct |
24 ms |
2252 KB |
Output is correct |
60 |
Correct |
26 ms |
2252 KB |
Output is correct |
61 |
Correct |
0 ms |
340 KB |
Output is correct |
62 |
Correct |
78 ms |
2632 KB |
Output is correct |
63 |
Correct |
106 ms |
3424 KB |
Output is correct |
64 |
Correct |
308 ms |
3012 KB |
Output is correct |
65 |
Correct |
1465 ms |
3556 KB |
Output is correct |
66 |
Execution timed out |
4065 ms |
4104 KB |
Time limit exceeded |
67 |
Halted |
0 ms |
0 KB |
- |