# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
708149 | 2023-03-11T06:26:08 Z | arcane | Bigger segments (IZhO19_segments) | C++17 | 303 ms | 48176 KB |
#include <bits/stdc++.h> using namespace std; #define int long long #define mp make_pair #define se second int32_t main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, ans = 0, tmp1 = -1e8, tot, pos; cin >> n; int arr[n], smol[n], pref[n + 1]; for (int i = 0; i < n; i++) cin >> arr[i]; pref[0] = 0; set <pair <int, int> > s; for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + arr[i]; for (int i = 0; i < n; i++){ smol[i] = pref[i + 1]; auto it = s.upper_bound(mp(pref[i + 1], (int)1e18)); if (it != s.begin()){ it--; smol[i] = min(smol[i], pref[i + 1] + (*it).se); } s.insert(mp(smol[i] + pref[i + 1], -pref[i + 1])); while ((*(s.rbegin())).se != -pref[i + 1]) s.erase(--s.end()); } tot = pref[n] - smol[n - 1]; pos = n - 1; ans = 1; while (tot){ while (pref[pos + 1] != tot){ pos--; } tot -= smol[pos]; ans += 1; } cout << ans << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 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 | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 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 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 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 | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 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 | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 324 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 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 | 320 KB | Output is correct |
25 | Correct | 1 ms | 324 KB | Output is correct |
26 | Correct | 1 ms | 324 KB | Output is correct |
27 | Correct | 1 ms | 320 KB | Output is correct |
28 | Correct | 1 ms | 324 KB | Output is correct |
29 | Correct | 1 ms | 324 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 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 | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 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 | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 324 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 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 | 320 KB | Output is correct |
25 | Correct | 1 ms | 324 KB | Output is correct |
26 | Correct | 1 ms | 324 KB | Output is correct |
27 | Correct | 1 ms | 320 KB | Output is correct |
28 | Correct | 1 ms | 324 KB | Output is correct |
29 | Correct | 1 ms | 324 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 1 ms | 468 KB | Output is correct |
32 | Correct | 1 ms | 460 KB | Output is correct |
33 | Correct | 1 ms | 336 KB | Output is correct |
34 | Correct | 1 ms | 588 KB | Output is correct |
35 | Correct | 1 ms | 588 KB | Output is correct |
36 | Correct | 1 ms | 548 KB | Output is correct |
37 | Correct | 1 ms | 468 KB | Output is correct |
38 | Correct | 1 ms | 468 KB | Output is correct |
39 | Correct | 1 ms | 468 KB | Output is correct |
40 | Correct | 2 ms | 548 KB | Output is correct |
41 | Correct | 1 ms | 468 KB | Output is correct |
42 | Correct | 1 ms | 452 KB | Output is correct |
43 | Correct | 1 ms | 468 KB | Output is correct |
44 | Correct | 2 ms | 468 KB | Output is correct |
45 | Correct | 1 ms | 468 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 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 | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 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 | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 324 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 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 | 320 KB | Output is correct |
25 | Correct | 1 ms | 324 KB | Output is correct |
26 | Correct | 1 ms | 324 KB | Output is correct |
27 | Correct | 1 ms | 320 KB | Output is correct |
28 | Correct | 1 ms | 324 KB | Output is correct |
29 | Correct | 1 ms | 324 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 1 ms | 468 KB | Output is correct |
32 | Correct | 1 ms | 460 KB | Output is correct |
33 | Correct | 1 ms | 336 KB | Output is correct |
34 | Correct | 1 ms | 588 KB | Output is correct |
35 | Correct | 1 ms | 588 KB | Output is correct |
36 | Correct | 1 ms | 548 KB | Output is correct |
37 | Correct | 1 ms | 468 KB | Output is correct |
38 | Correct | 1 ms | 468 KB | Output is correct |
39 | Correct | 1 ms | 468 KB | Output is correct |
40 | Correct | 2 ms | 548 KB | Output is correct |
41 | Correct | 1 ms | 468 KB | Output is correct |
42 | Correct | 1 ms | 452 KB | Output is correct |
43 | Correct | 1 ms | 468 KB | Output is correct |
44 | Correct | 2 ms | 468 KB | Output is correct |
45 | Correct | 1 ms | 468 KB | Output is correct |
46 | Correct | 39 ms | 9276 KB | Output is correct |
47 | Correct | 33 ms | 7348 KB | Output is correct |
48 | Correct | 28 ms | 3788 KB | Output is correct |
49 | Correct | 43 ms | 6904 KB | Output is correct |
50 | Correct | 46 ms | 9784 KB | Output is correct |
51 | Correct | 39 ms | 8488 KB | Output is correct |
52 | Correct | 18 ms | 4416 KB | Output is correct |
53 | Correct | 11 ms | 2764 KB | Output is correct |
54 | Correct | 40 ms | 7436 KB | Output is correct |
55 | Correct | 43 ms | 9296 KB | Output is correct |
56 | Correct | 43 ms | 9348 KB | Output is correct |
57 | Correct | 38 ms | 8692 KB | Output is correct |
58 | Correct | 38 ms | 8640 KB | Output is correct |
59 | Correct | 51 ms | 9520 KB | Output is correct |
60 | Correct | 45 ms | 9412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 0 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 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 | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 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 | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 324 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 340 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 | 320 KB | Output is correct |
25 | Correct | 1 ms | 324 KB | Output is correct |
26 | Correct | 1 ms | 324 KB | Output is correct |
27 | Correct | 1 ms | 320 KB | Output is correct |
28 | Correct | 1 ms | 324 KB | Output is correct |
29 | Correct | 1 ms | 324 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 1 ms | 468 KB | Output is correct |
32 | Correct | 1 ms | 460 KB | Output is correct |
33 | Correct | 1 ms | 336 KB | Output is correct |
34 | Correct | 1 ms | 588 KB | Output is correct |
35 | Correct | 1 ms | 588 KB | Output is correct |
36 | Correct | 1 ms | 548 KB | Output is correct |
37 | Correct | 1 ms | 468 KB | Output is correct |
38 | Correct | 1 ms | 468 KB | Output is correct |
39 | Correct | 1 ms | 468 KB | Output is correct |
40 | Correct | 2 ms | 548 KB | Output is correct |
41 | Correct | 1 ms | 468 KB | Output is correct |
42 | Correct | 1 ms | 452 KB | Output is correct |
43 | Correct | 1 ms | 468 KB | Output is correct |
44 | Correct | 2 ms | 468 KB | Output is correct |
45 | Correct | 1 ms | 468 KB | Output is correct |
46 | Correct | 39 ms | 9276 KB | Output is correct |
47 | Correct | 33 ms | 7348 KB | Output is correct |
48 | Correct | 28 ms | 3788 KB | Output is correct |
49 | Correct | 43 ms | 6904 KB | Output is correct |
50 | Correct | 46 ms | 9784 KB | Output is correct |
51 | Correct | 39 ms | 8488 KB | Output is correct |
52 | Correct | 18 ms | 4416 KB | Output is correct |
53 | Correct | 11 ms | 2764 KB | Output is correct |
54 | Correct | 40 ms | 7436 KB | Output is correct |
55 | Correct | 43 ms | 9296 KB | Output is correct |
56 | Correct | 43 ms | 9348 KB | Output is correct |
57 | Correct | 38 ms | 8692 KB | Output is correct |
58 | Correct | 38 ms | 8640 KB | Output is correct |
59 | Correct | 51 ms | 9520 KB | Output is correct |
60 | Correct | 45 ms | 9412 KB | Output is correct |
61 | Correct | 217 ms | 45368 KB | Output is correct |
62 | Correct | 216 ms | 45260 KB | Output is correct |
63 | Correct | 176 ms | 37240 KB | Output is correct |
64 | Correct | 215 ms | 22772 KB | Output is correct |
65 | Correct | 253 ms | 48176 KB | Output is correct |
66 | Correct | 218 ms | 41764 KB | Output is correct |
67 | Correct | 176 ms | 33408 KB | Output is correct |
68 | Correct | 97 ms | 16756 KB | Output is correct |
69 | Correct | 188 ms | 35800 KB | Output is correct |
70 | Correct | 267 ms | 45612 KB | Output is correct |
71 | Correct | 259 ms | 45260 KB | Output is correct |
72 | Correct | 235 ms | 39412 KB | Output is correct |
73 | Correct | 242 ms | 41600 KB | Output is correct |
74 | Correct | 303 ms | 46592 KB | Output is correct |
75 | Correct | 261 ms | 46708 KB | Output is correct |