Submission #342557

# Submission time Handle Problem Language Result Execution time Memory
342557 2021-01-02T11:09:06 Z dimashii Bigger segments (IZhO19_segments) C++17
100 / 100
364 ms 44524 KB
#include <bits/stdc++.h>

#define f first
#define s second

#define fastio ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define ll long long

using namespace std;

const int mxN = 1e6 + 45, mod = 1e9 + 7;
const ll inf = 2e18 + 43;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, a[mxN], dp[mxN];

ll p[mxN];

set <pair <ll, int> > st;

void add(int idx, ll sum) {
	if (st.empty()) {
		st.insert({sum, idx});
		return;
	}
	auto it = st.lower_bound({sum + 1, 0});
	vector <pair <ll, int> > del;
	while (it != st.end()) del.push_back(*(it++));
	for (auto x : del) st.erase(x);
	st.insert({sum, idx});
}

int get(int idx, ll sum) {
	auto it = st.lower_bound({sum + 1, 0});
	it--;
	return it -> second;
}

int main() {
	fastio;
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> a[i], p[i] = p[i - 1] + a[i];
	add(0, 0);
	for (int i = 1; i <= n; ++i) {
		int L = get(i, p[i]);
		dp[i] = dp[L] + 1;
		add(i, p[i] * 2 - p[L]);
	}
	cout << dp[n];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 2 ms 620 KB Output is correct
36 Correct 2 ms 620 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 2 ms 620 KB Output is correct
40 Correct 2 ms 620 KB Output is correct
41 Correct 2 ms 620 KB Output is correct
42 Correct 2 ms 640 KB Output is correct
43 Correct 2 ms 620 KB Output is correct
44 Correct 2 ms 640 KB Output is correct
45 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 2 ms 620 KB Output is correct
36 Correct 2 ms 620 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 2 ms 620 KB Output is correct
40 Correct 2 ms 620 KB Output is correct
41 Correct 2 ms 620 KB Output is correct
42 Correct 2 ms 640 KB Output is correct
43 Correct 2 ms 620 KB Output is correct
44 Correct 2 ms 640 KB Output is correct
45 Correct 2 ms 620 KB Output is correct
46 Correct 52 ms 8556 KB Output is correct
47 Correct 56 ms 6808 KB Output is correct
48 Correct 48 ms 3456 KB Output is correct
49 Correct 67 ms 6764 KB Output is correct
50 Correct 58 ms 9196 KB Output is correct
51 Correct 64 ms 7916 KB Output is correct
52 Correct 29 ms 4076 KB Output is correct
53 Correct 17 ms 2668 KB Output is correct
54 Correct 54 ms 6892 KB Output is correct
55 Correct 62 ms 8556 KB Output is correct
56 Correct 54 ms 8684 KB Output is correct
57 Correct 56 ms 8680 KB Output is correct
58 Correct 52 ms 8020 KB Output is correct
59 Correct 55 ms 8832 KB Output is correct
60 Correct 55 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 2 ms 620 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 620 KB Output is correct
35 Correct 2 ms 620 KB Output is correct
36 Correct 2 ms 620 KB Output is correct
37 Correct 2 ms 492 KB Output is correct
38 Correct 1 ms 492 KB Output is correct
39 Correct 2 ms 620 KB Output is correct
40 Correct 2 ms 620 KB Output is correct
41 Correct 2 ms 620 KB Output is correct
42 Correct 2 ms 640 KB Output is correct
43 Correct 2 ms 620 KB Output is correct
44 Correct 2 ms 640 KB Output is correct
45 Correct 2 ms 620 KB Output is correct
46 Correct 52 ms 8556 KB Output is correct
47 Correct 56 ms 6808 KB Output is correct
48 Correct 48 ms 3456 KB Output is correct
49 Correct 67 ms 6764 KB Output is correct
50 Correct 58 ms 9196 KB Output is correct
51 Correct 64 ms 7916 KB Output is correct
52 Correct 29 ms 4076 KB Output is correct
53 Correct 17 ms 2668 KB Output is correct
54 Correct 54 ms 6892 KB Output is correct
55 Correct 62 ms 8556 KB Output is correct
56 Correct 54 ms 8684 KB Output is correct
57 Correct 56 ms 8680 KB Output is correct
58 Correct 52 ms 8020 KB Output is correct
59 Correct 55 ms 8832 KB Output is correct
60 Correct 55 ms 8684 KB Output is correct
61 Correct 286 ms 41452 KB Output is correct
62 Correct 300 ms 41484 KB Output is correct
63 Correct 310 ms 33928 KB Output is correct
64 Correct 364 ms 19064 KB Output is correct
65 Correct 336 ms 44524 KB Output is correct
66 Correct 348 ms 37868 KB Output is correct
67 Correct 272 ms 30444 KB Output is correct
68 Correct 131 ms 15340 KB Output is correct
69 Correct 320 ms 33132 KB Output is correct
70 Correct 358 ms 41836 KB Output is correct
71 Correct 311 ms 41452 KB Output is correct
72 Correct 312 ms 37472 KB Output is correct
73 Correct 314 ms 37848 KB Output is correct
74 Correct 317 ms 42860 KB Output is correct
75 Correct 321 ms 42732 KB Output is correct