Submission #344850

# Submission time Handle Problem Language Result Execution time Memory
344850 2021-01-06T16:16:07 Z dimashii Money (IZhO17_money) C++17
100 / 100
1498 ms 56868 KB
#include <bits/stdc++.h>

using namespace std;

const int mxN = 1e6 + 123;

int A[mxN], B[mxN], R[mxN];

int main() {
	ios_base :: sync_with_stdio(false); cin.tie(nullptr); 
	int N; cin >> N;
	for (int i = 1; i <= N; ++i) cin >> A[i];
	R[N] = N;
	for (int i = N - 1; i > 0; i--) {
		if (A[i] <= A[i + 1]) R[i] = R[i + 1];
		else R[i] = i;
	}
	set <int> st;
	int ans = 0;
	for (int i = 1; i <= N; ++i) {
		++ans;
		if (i == 1) {
			for (int j = i; j <= R[i]; ++j) st.insert(A[j]);
			i = R[i];
			continue;
		}
		if (A[i] >= *(--st.end())) {
			for (int j = i; j <= R[i]; ++j) st.insert(A[j]);
			i = R[i];
			continue;
		}int lb = i, rb = R[i], j = i;
		int l = *st.upper_bound(A[i]);
		int mn = *st.begin();
		while (rb >= lb) {
			int md = (lb + rb) / 2;
			// can or not
			if (A[md] <= mn) {
				j = md;
				lb = md + 1;
				continue;
			}
			int r = *(--st.lower_bound(A[md]));
			if (l > r) {
				j = md;
				lb = md + 1;
			}else rb = md - 1;
		}
		for (int k = i; k <= j; ++k) st.insert(A[k]);
		i = j;
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 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 364 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 0 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 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 364 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 0 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 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 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 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 0 ms 364 KB Output is correct
14 Correct 0 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 364 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 0 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 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 73 ms 4204 KB Output is correct
40 Correct 121 ms 6604 KB Output is correct
41 Correct 51 ms 3436 KB Output is correct
42 Correct 55 ms 3180 KB Output is correct
43 Correct 40 ms 2284 KB Output is correct
44 Correct 147 ms 8356 KB Output is correct
45 Correct 136 ms 8300 KB Output is correct
46 Correct 145 ms 8172 KB Output is correct
47 Correct 121 ms 8172 KB Output is correct
48 Correct 127 ms 8172 KB Output is correct
49 Correct 706 ms 26604 KB Output is correct
50 Correct 684 ms 26732 KB Output is correct
51 Correct 681 ms 26860 KB Output is correct
52 Correct 679 ms 26708 KB Output is correct
53 Correct 743 ms 26732 KB Output is correct
54 Correct 676 ms 26716 KB Output is correct
55 Correct 1489 ms 55500 KB Output is correct
56 Correct 1494 ms 56760 KB Output is correct
57 Correct 1498 ms 56764 KB Output is correct
58 Correct 1488 ms 56868 KB Output is correct
59 Correct 1475 ms 56640 KB Output is correct
60 Correct 1462 ms 56624 KB Output is correct
61 Correct 1485 ms 56740 KB Output is correct
62 Correct 1486 ms 56840 KB Output is correct