#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
const int INF = 1e9;
int N, Q;
vi L;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
L.resize(N);
for (int i = 0; i < N; ++i)
cin >> L[i];
cin >> Q;
while (Q--)
{
ll x, y, a, b;
cin >> x >> y >> a >> b;
--x;
L[x] = y;
vi B(L.begin() + a, L.begin() + b);
// starting with lower piece
vi dp(sz(B), -INF); // dp[i] := number of zigzag pieces in prefix i with i as minimum
dp[0] = 1;
for (int i = 1; i < sz(B); ++i)
{
ll buffer = 0;
for (int j = i - 1; j >= 0; --j)
{
buffer += B[j];
if (buffer > B[i])
{
dp[i] = max(dp[i], 2LL);
if (j > 0 && buffer > B[j - 1])
dp[i] = max(dp[i], dp[j - 1] + 2);
}
}
}
ll ans = max(1LL, dp.back());
ll buffer = 0;
for (int i = sz(B) - 1; i > 0; --i)
{
buffer += B[i];
if (buffer > B[i - 1])
ans = max(ans, dp[i - 1] + 1);
}
cout << ans << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 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 |
320 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 |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 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 |
320 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 |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
312 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 |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
328 KB |
Output is correct |
26 |
Correct |
11 ms |
376 KB |
Output is correct |
27 |
Correct |
11 ms |
372 KB |
Output is correct |
28 |
Correct |
11 ms |
388 KB |
Output is correct |
29 |
Correct |
9 ms |
340 KB |
Output is correct |
30 |
Correct |
7 ms |
340 KB |
Output is correct |
31 |
Correct |
8 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
340 KB |
Output is correct |
34 |
Correct |
8 ms |
372 KB |
Output is correct |
35 |
Correct |
9 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
340 KB |
Output is correct |
37 |
Correct |
11 ms |
376 KB |
Output is correct |
38 |
Correct |
4 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 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 |
320 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 |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
312 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 |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
328 KB |
Output is correct |
26 |
Correct |
11 ms |
376 KB |
Output is correct |
27 |
Correct |
11 ms |
372 KB |
Output is correct |
28 |
Correct |
11 ms |
388 KB |
Output is correct |
29 |
Correct |
9 ms |
340 KB |
Output is correct |
30 |
Correct |
7 ms |
340 KB |
Output is correct |
31 |
Correct |
8 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
340 KB |
Output is correct |
34 |
Correct |
8 ms |
372 KB |
Output is correct |
35 |
Correct |
9 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
340 KB |
Output is correct |
37 |
Correct |
11 ms |
376 KB |
Output is correct |
38 |
Correct |
4 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
18 ms |
3912 KB |
Output is correct |
42 |
Correct |
20 ms |
4316 KB |
Output is correct |
43 |
Correct |
68 ms |
4184 KB |
Output is correct |
44 |
Correct |
436 ms |
3632 KB |
Output is correct |
45 |
Execution timed out |
4033 ms |
5836 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
227 ms |
4952 KB |
Output is correct |
3 |
Execution timed out |
4062 ms |
6032 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
214 ms |
4892 KB |
Output is correct |
4 |
Execution timed out |
4043 ms |
5104 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 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 |
320 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 |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
1 ms |
320 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
320 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
324 KB |
Output is correct |
19 |
Correct |
1 ms |
312 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 |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
328 KB |
Output is correct |
26 |
Correct |
11 ms |
376 KB |
Output is correct |
27 |
Correct |
11 ms |
372 KB |
Output is correct |
28 |
Correct |
11 ms |
388 KB |
Output is correct |
29 |
Correct |
9 ms |
340 KB |
Output is correct |
30 |
Correct |
7 ms |
340 KB |
Output is correct |
31 |
Correct |
8 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Correct |
6 ms |
340 KB |
Output is correct |
34 |
Correct |
8 ms |
372 KB |
Output is correct |
35 |
Correct |
9 ms |
340 KB |
Output is correct |
36 |
Correct |
5 ms |
340 KB |
Output is correct |
37 |
Correct |
11 ms |
376 KB |
Output is correct |
38 |
Correct |
4 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
18 ms |
3912 KB |
Output is correct |
42 |
Correct |
20 ms |
4316 KB |
Output is correct |
43 |
Correct |
68 ms |
4184 KB |
Output is correct |
44 |
Correct |
436 ms |
3632 KB |
Output is correct |
45 |
Execution timed out |
4033 ms |
5836 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |