#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 C = 70;
pii operator+(const pii &a, const pii &b) { return pii(a.X + b.X, a.Y + b.Y); }
int arr[250005], lft[250005], tmp[250005];
struct Node {
int l, r;
pii mx[C + 1]; // mx[i]: start with (l - i - 1, 0), jump to (i + mx[i].X, mx[i].Y)
Node() {}
Node(int v): l(v), r(v) {
for (int i = 0; i <= C; ++i) {
mx[i] = pii(0, 0);
if (lft[v] - 1 > v - i - 1) mx[i] = pii(i + 1, 2);
}
}
Node operator+(const Node &a) const {
Node res(*this);
res.r = a.r;
for (int i = 0; i <= C; ++i) {
if (res.l - i - 1 + res.mx[i].X < a.l - C - 1) res.mx[i] = res.mx[i] + a.mx[C];
else res.mx[i] = res.mx[i] + a.mx[a.l - (res.l - i - 1 + res.mx[i].X) - 1];
}
return res;
}
} seg[1000005];
void build(int l, int r, int rt) {
if (l == r) return seg[rt] = Node(l), void();
int mid = (l + r) >> 1;
build(l, mid, rt << 1), build(mid + 1, r, rt << 1 | 1);
seg[rt] = seg[rt << 1] + seg[rt << 1 | 1];
}
void modify(int L, int R, int rt) {
if (seg[rt].l == seg[rt].r) return seg[rt] = Node(seg[rt].l), void();
int mid = (seg[rt].l + seg[rt].r) >> 1;
if (L <= mid) modify(L, R, rt << 1);
if (R > mid) modify(L, R, rt << 1 | 1);
seg[rt] = seg[rt << 1] + seg[rt << 1 | 1];
}
Node query(int L, int R, int rt) {
if (L <= seg[rt].l && R >= seg[rt].r) return seg[rt];
int mid = (seg[rt].l + seg[rt].r) >> 1;
if (R <= mid) return query(L, R, rt << 1);
if (L > mid) return query(L, R, rt << 1 | 1);
return query(L, R, rt << 1) + query(L, R, rt << 1 | 1);
}
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] = -C - 1;
ll cur = 0;
for (int j = i; j > 0 && j > i - C; --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);
build(1, n, 1);
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 + C; ++j)
update(j);
modify(max(1, x - 1), min(n, x + C), 1);
ll cur = 0;
for (int j = a + 1; j < b && j <= a + C; ++j) {
tmp[j] = lft[j];
cur += arr[j];
if (cur > arr[j + 1]) lft[j] = max(lft[j], a + 1);
}
if (a + 1 <= min(b - 1, a + C))
modify(a + 1, min(b - 1, a + C), 1);
tmp[b] = lft[b], lft[b] = 0, cur = 0;
for (int j = b; j > a && j > b - C; --j) {
cur += arr[j];
if (j == a + 1 || cur > arr[j - 1]) {
lft[b] = j;
break;
}
}
modify(b, b, 1);
int ans = 1;
Node res = query(a + 1, b, 1);
if (res.mx[1].X + a + 1 - 1 - 1 == b) ans = max(ans, res.mx[1].Y - 1);
else ans = max(ans, res.mx[1].Y);
if (res.mx[0].X + a + 1 - 0 - 1 == b) ans = max(ans, res.mx[0].Y);
else ans = max(ans, res.mx[0].Y + 1);
for (int j = a + 1; j <= b && j <= a + C; ++j)
lft[j] = tmp[j];
if (a + 1 <= min(b - 1, a + C))
modify(a + 1, min(b - 1, a + C), 1);
lft[b] = tmp[b];
modify(b, b, 1);
cout << ans << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
563876 KB |
Output is correct |
2 |
Correct |
248 ms |
563896 KB |
Output is correct |
3 |
Correct |
248 ms |
563916 KB |
Output is correct |
4 |
Correct |
332 ms |
563876 KB |
Output is correct |
5 |
Correct |
257 ms |
563824 KB |
Output is correct |
6 |
Correct |
254 ms |
563904 KB |
Output is correct |
7 |
Correct |
254 ms |
563864 KB |
Output is correct |
8 |
Correct |
253 ms |
563952 KB |
Output is correct |
9 |
Correct |
259 ms |
563916 KB |
Output is correct |
10 |
Correct |
255 ms |
563828 KB |
Output is correct |
11 |
Correct |
255 ms |
563868 KB |
Output is correct |
12 |
Correct |
253 ms |
563860 KB |
Output is correct |
13 |
Correct |
257 ms |
563940 KB |
Output is correct |
14 |
Correct |
261 ms |
563864 KB |
Output is correct |
15 |
Correct |
257 ms |
563812 KB |
Output is correct |
16 |
Correct |
249 ms |
563896 KB |
Output is correct |
17 |
Correct |
251 ms |
563916 KB |
Output is correct |
18 |
Correct |
254 ms |
563928 KB |
Output is correct |
19 |
Correct |
258 ms |
563848 KB |
Output is correct |
20 |
Correct |
253 ms |
563852 KB |
Output is correct |
21 |
Correct |
263 ms |
563892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
563876 KB |
Output is correct |
2 |
Correct |
248 ms |
563896 KB |
Output is correct |
3 |
Correct |
248 ms |
563916 KB |
Output is correct |
4 |
Correct |
332 ms |
563876 KB |
Output is correct |
5 |
Correct |
257 ms |
563824 KB |
Output is correct |
6 |
Correct |
254 ms |
563904 KB |
Output is correct |
7 |
Correct |
254 ms |
563864 KB |
Output is correct |
8 |
Correct |
253 ms |
563952 KB |
Output is correct |
9 |
Correct |
259 ms |
563916 KB |
Output is correct |
10 |
Correct |
255 ms |
563828 KB |
Output is correct |
11 |
Correct |
255 ms |
563868 KB |
Output is correct |
12 |
Correct |
253 ms |
563860 KB |
Output is correct |
13 |
Correct |
257 ms |
563940 KB |
Output is correct |
14 |
Correct |
261 ms |
563864 KB |
Output is correct |
15 |
Correct |
257 ms |
563812 KB |
Output is correct |
16 |
Correct |
249 ms |
563896 KB |
Output is correct |
17 |
Correct |
251 ms |
563916 KB |
Output is correct |
18 |
Correct |
254 ms |
563928 KB |
Output is correct |
19 |
Correct |
258 ms |
563848 KB |
Output is correct |
20 |
Correct |
253 ms |
563852 KB |
Output is correct |
21 |
Correct |
263 ms |
563892 KB |
Output is correct |
22 |
Correct |
271 ms |
563904 KB |
Output is correct |
23 |
Correct |
258 ms |
563996 KB |
Output is correct |
24 |
Correct |
271 ms |
563892 KB |
Output is correct |
25 |
Correct |
252 ms |
563860 KB |
Output is correct |
26 |
Correct |
255 ms |
563940 KB |
Output is correct |
27 |
Correct |
266 ms |
563856 KB |
Output is correct |
28 |
Correct |
264 ms |
563932 KB |
Output is correct |
29 |
Correct |
267 ms |
563932 KB |
Output is correct |
30 |
Correct |
255 ms |
564044 KB |
Output is correct |
31 |
Correct |
256 ms |
563916 KB |
Output is correct |
32 |
Correct |
256 ms |
563980 KB |
Output is correct |
33 |
Correct |
257 ms |
564020 KB |
Output is correct |
34 |
Correct |
256 ms |
563948 KB |
Output is correct |
35 |
Correct |
253 ms |
563844 KB |
Output is correct |
36 |
Correct |
268 ms |
563968 KB |
Output is correct |
37 |
Correct |
255 ms |
563944 KB |
Output is correct |
38 |
Correct |
258 ms |
563944 KB |
Output is correct |
39 |
Correct |
264 ms |
563916 KB |
Output is correct |
40 |
Correct |
254 ms |
563860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
563876 KB |
Output is correct |
2 |
Correct |
248 ms |
563896 KB |
Output is correct |
3 |
Correct |
248 ms |
563916 KB |
Output is correct |
4 |
Correct |
332 ms |
563876 KB |
Output is correct |
5 |
Correct |
257 ms |
563824 KB |
Output is correct |
6 |
Correct |
254 ms |
563904 KB |
Output is correct |
7 |
Correct |
254 ms |
563864 KB |
Output is correct |
8 |
Correct |
253 ms |
563952 KB |
Output is correct |
9 |
Correct |
259 ms |
563916 KB |
Output is correct |
10 |
Correct |
255 ms |
563828 KB |
Output is correct |
11 |
Correct |
255 ms |
563868 KB |
Output is correct |
12 |
Correct |
253 ms |
563860 KB |
Output is correct |
13 |
Correct |
257 ms |
563940 KB |
Output is correct |
14 |
Correct |
261 ms |
563864 KB |
Output is correct |
15 |
Correct |
257 ms |
563812 KB |
Output is correct |
16 |
Correct |
249 ms |
563896 KB |
Output is correct |
17 |
Correct |
251 ms |
563916 KB |
Output is correct |
18 |
Correct |
254 ms |
563928 KB |
Output is correct |
19 |
Correct |
258 ms |
563848 KB |
Output is correct |
20 |
Correct |
253 ms |
563852 KB |
Output is correct |
21 |
Correct |
263 ms |
563892 KB |
Output is correct |
22 |
Correct |
271 ms |
563904 KB |
Output is correct |
23 |
Correct |
258 ms |
563996 KB |
Output is correct |
24 |
Correct |
271 ms |
563892 KB |
Output is correct |
25 |
Correct |
252 ms |
563860 KB |
Output is correct |
26 |
Correct |
255 ms |
563940 KB |
Output is correct |
27 |
Correct |
266 ms |
563856 KB |
Output is correct |
28 |
Correct |
264 ms |
563932 KB |
Output is correct |
29 |
Correct |
267 ms |
563932 KB |
Output is correct |
30 |
Correct |
255 ms |
564044 KB |
Output is correct |
31 |
Correct |
256 ms |
563916 KB |
Output is correct |
32 |
Correct |
256 ms |
563980 KB |
Output is correct |
33 |
Correct |
257 ms |
564020 KB |
Output is correct |
34 |
Correct |
256 ms |
563948 KB |
Output is correct |
35 |
Correct |
253 ms |
563844 KB |
Output is correct |
36 |
Correct |
268 ms |
563968 KB |
Output is correct |
37 |
Correct |
255 ms |
563944 KB |
Output is correct |
38 |
Correct |
258 ms |
563944 KB |
Output is correct |
39 |
Correct |
264 ms |
563916 KB |
Output is correct |
40 |
Correct |
254 ms |
563860 KB |
Output is correct |
41 |
Correct |
376 ms |
565612 KB |
Output is correct |
42 |
Correct |
391 ms |
565924 KB |
Output is correct |
43 |
Correct |
382 ms |
566016 KB |
Output is correct |
44 |
Correct |
385 ms |
565320 KB |
Output is correct |
45 |
Correct |
387 ms |
565852 KB |
Output is correct |
46 |
Correct |
385 ms |
565872 KB |
Output is correct |
47 |
Correct |
355 ms |
565392 KB |
Output is correct |
48 |
Correct |
391 ms |
565940 KB |
Output is correct |
49 |
Correct |
382 ms |
565928 KB |
Output is correct |
50 |
Correct |
389 ms |
565876 KB |
Output is correct |
51 |
Correct |
384 ms |
565840 KB |
Output is correct |
52 |
Correct |
365 ms |
565488 KB |
Output is correct |
53 |
Correct |
383 ms |
565880 KB |
Output is correct |
54 |
Correct |
381 ms |
565964 KB |
Output is correct |
55 |
Correct |
372 ms |
565904 KB |
Output is correct |
56 |
Correct |
388 ms |
566052 KB |
Output is correct |
57 |
Correct |
379 ms |
565872 KB |
Output is correct |
58 |
Correct |
426 ms |
565876 KB |
Output is correct |
59 |
Correct |
391 ms |
565820 KB |
Output is correct |
60 |
Correct |
383 ms |
566004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
257 ms |
563852 KB |
Output is correct |
2 |
Execution timed out |
4123 ms |
566216 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
563924 KB |
Output is correct |
2 |
Correct |
253 ms |
563812 KB |
Output is correct |
3 |
Execution timed out |
4090 ms |
566884 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
563876 KB |
Output is correct |
2 |
Correct |
248 ms |
563896 KB |
Output is correct |
3 |
Correct |
248 ms |
563916 KB |
Output is correct |
4 |
Correct |
332 ms |
563876 KB |
Output is correct |
5 |
Correct |
257 ms |
563824 KB |
Output is correct |
6 |
Correct |
254 ms |
563904 KB |
Output is correct |
7 |
Correct |
254 ms |
563864 KB |
Output is correct |
8 |
Correct |
253 ms |
563952 KB |
Output is correct |
9 |
Correct |
259 ms |
563916 KB |
Output is correct |
10 |
Correct |
255 ms |
563828 KB |
Output is correct |
11 |
Correct |
255 ms |
563868 KB |
Output is correct |
12 |
Correct |
253 ms |
563860 KB |
Output is correct |
13 |
Correct |
257 ms |
563940 KB |
Output is correct |
14 |
Correct |
261 ms |
563864 KB |
Output is correct |
15 |
Correct |
257 ms |
563812 KB |
Output is correct |
16 |
Correct |
249 ms |
563896 KB |
Output is correct |
17 |
Correct |
251 ms |
563916 KB |
Output is correct |
18 |
Correct |
254 ms |
563928 KB |
Output is correct |
19 |
Correct |
258 ms |
563848 KB |
Output is correct |
20 |
Correct |
253 ms |
563852 KB |
Output is correct |
21 |
Correct |
263 ms |
563892 KB |
Output is correct |
22 |
Correct |
271 ms |
563904 KB |
Output is correct |
23 |
Correct |
258 ms |
563996 KB |
Output is correct |
24 |
Correct |
271 ms |
563892 KB |
Output is correct |
25 |
Correct |
252 ms |
563860 KB |
Output is correct |
26 |
Correct |
255 ms |
563940 KB |
Output is correct |
27 |
Correct |
266 ms |
563856 KB |
Output is correct |
28 |
Correct |
264 ms |
563932 KB |
Output is correct |
29 |
Correct |
267 ms |
563932 KB |
Output is correct |
30 |
Correct |
255 ms |
564044 KB |
Output is correct |
31 |
Correct |
256 ms |
563916 KB |
Output is correct |
32 |
Correct |
256 ms |
563980 KB |
Output is correct |
33 |
Correct |
257 ms |
564020 KB |
Output is correct |
34 |
Correct |
256 ms |
563948 KB |
Output is correct |
35 |
Correct |
253 ms |
563844 KB |
Output is correct |
36 |
Correct |
268 ms |
563968 KB |
Output is correct |
37 |
Correct |
255 ms |
563944 KB |
Output is correct |
38 |
Correct |
258 ms |
563944 KB |
Output is correct |
39 |
Correct |
264 ms |
563916 KB |
Output is correct |
40 |
Correct |
254 ms |
563860 KB |
Output is correct |
41 |
Correct |
376 ms |
565612 KB |
Output is correct |
42 |
Correct |
391 ms |
565924 KB |
Output is correct |
43 |
Correct |
382 ms |
566016 KB |
Output is correct |
44 |
Correct |
385 ms |
565320 KB |
Output is correct |
45 |
Correct |
387 ms |
565852 KB |
Output is correct |
46 |
Correct |
385 ms |
565872 KB |
Output is correct |
47 |
Correct |
355 ms |
565392 KB |
Output is correct |
48 |
Correct |
391 ms |
565940 KB |
Output is correct |
49 |
Correct |
382 ms |
565928 KB |
Output is correct |
50 |
Correct |
389 ms |
565876 KB |
Output is correct |
51 |
Correct |
384 ms |
565840 KB |
Output is correct |
52 |
Correct |
365 ms |
565488 KB |
Output is correct |
53 |
Correct |
383 ms |
565880 KB |
Output is correct |
54 |
Correct |
381 ms |
565964 KB |
Output is correct |
55 |
Correct |
372 ms |
565904 KB |
Output is correct |
56 |
Correct |
388 ms |
566052 KB |
Output is correct |
57 |
Correct |
379 ms |
565872 KB |
Output is correct |
58 |
Correct |
426 ms |
565876 KB |
Output is correct |
59 |
Correct |
391 ms |
565820 KB |
Output is correct |
60 |
Correct |
383 ms |
566004 KB |
Output is correct |
61 |
Correct |
257 ms |
563852 KB |
Output is correct |
62 |
Execution timed out |
4123 ms |
566216 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |