#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
int arr[250005], dp[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];
int q;
cin >> q;
for (int i = 1; i <= q; ++i) {
int x, y, a, b;
cin >> x >> y >> a >> b;
arr[x] = y;
int ans = 1;
ll cur = 0, sum = 0;
for (int j = a + 1; j <= b; ++j) sum += arr[j];
for (int j = a + 1; j <= b; ++j) {
dp[j] = -n;
if (j == a + 1) dp[j] = 1;
if (cur > arr[j]) dp[j] = 2;
ll nw = 0;
for (int k = j - 1; k > a && k > j - 70; --k) {
if (nw > arr[k] && nw > arr[j]) dp[j] = max(dp[j], dp[k] + 2);
nw += arr[k];
}
cur += arr[j];
if (sum - cur > arr[j]) ans = max(ans, dp[j] + 1);
if (j == b) ans = max(ans, dp[j]);
}
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 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 |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
352 KB |
Output is correct |
34 |
Correct |
3 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 |
3 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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 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 |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
352 KB |
Output is correct |
34 |
Correct |
3 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 |
3 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 |
23 ms |
3184 KB |
Output is correct |
42 |
Correct |
23 ms |
3404 KB |
Output is correct |
43 |
Correct |
26 ms |
3276 KB |
Output is correct |
44 |
Correct |
23 ms |
2636 KB |
Output is correct |
45 |
Correct |
77 ms |
4384 KB |
Output is correct |
46 |
Correct |
175 ms |
3572 KB |
Output is correct |
47 |
Correct |
149 ms |
3212 KB |
Output is correct |
48 |
Correct |
215 ms |
3928 KB |
Output is correct |
49 |
Correct |
257 ms |
3768 KB |
Output is correct |
50 |
Correct |
179 ms |
3636 KB |
Output is correct |
51 |
Correct |
160 ms |
3532 KB |
Output is correct |
52 |
Correct |
120 ms |
3440 KB |
Output is correct |
53 |
Correct |
260 ms |
4556 KB |
Output is correct |
54 |
Correct |
236 ms |
3520 KB |
Output is correct |
55 |
Correct |
204 ms |
3320 KB |
Output is correct |
56 |
Correct |
173 ms |
3672 KB |
Output is correct |
57 |
Correct |
123 ms |
3208 KB |
Output is correct |
58 |
Correct |
186 ms |
3372 KB |
Output is correct |
59 |
Correct |
57 ms |
4072 KB |
Output is correct |
60 |
Correct |
92 ms |
4124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
286 ms |
1896 KB |
Output is correct |
3 |
Correct |
2549 ms |
2468 KB |
Output is correct |
4 |
Execution timed out |
4041 ms |
2412 KB |
Time limit exceeded |
5 |
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 |
264 ms |
2496 KB |
Output is correct |
4 |
Correct |
2615 ms |
2552 KB |
Output is correct |
5 |
Execution timed out |
4070 ms |
2328 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
328 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 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 |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
2 ms |
352 KB |
Output is correct |
34 |
Correct |
3 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 |
3 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 |
23 ms |
3184 KB |
Output is correct |
42 |
Correct |
23 ms |
3404 KB |
Output is correct |
43 |
Correct |
26 ms |
3276 KB |
Output is correct |
44 |
Correct |
23 ms |
2636 KB |
Output is correct |
45 |
Correct |
77 ms |
4384 KB |
Output is correct |
46 |
Correct |
175 ms |
3572 KB |
Output is correct |
47 |
Correct |
149 ms |
3212 KB |
Output is correct |
48 |
Correct |
215 ms |
3928 KB |
Output is correct |
49 |
Correct |
257 ms |
3768 KB |
Output is correct |
50 |
Correct |
179 ms |
3636 KB |
Output is correct |
51 |
Correct |
160 ms |
3532 KB |
Output is correct |
52 |
Correct |
120 ms |
3440 KB |
Output is correct |
53 |
Correct |
260 ms |
4556 KB |
Output is correct |
54 |
Correct |
236 ms |
3520 KB |
Output is correct |
55 |
Correct |
204 ms |
3320 KB |
Output is correct |
56 |
Correct |
173 ms |
3672 KB |
Output is correct |
57 |
Correct |
123 ms |
3208 KB |
Output is correct |
58 |
Correct |
186 ms |
3372 KB |
Output is correct |
59 |
Correct |
57 ms |
4072 KB |
Output is correct |
60 |
Correct |
92 ms |
4124 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
286 ms |
1896 KB |
Output is correct |
63 |
Correct |
2549 ms |
2468 KB |
Output is correct |
64 |
Execution timed out |
4041 ms |
2412 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |