Submission #344832

# Submission time Handle Problem Language Result Execution time Memory
344832 2021-01-06T15:47:15 Z dimashii Money (IZhO17_money) C++17
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>

using namespace std;

const int mxN = 1e6 + 1;

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

void Upd(int pos) {
	for (int i = pos; i < mxN; i |= i + 1) ++f[i];
}

int Get(int pos) {
	int ans = 0;
	for (int i = pos; i >= 0; i &= i + 1, --i) ans += f[i];
	return ans;
}

int Count(int l, int r) {
	if (l > r) return 0;
	return Get(r) - Get(l - 1);
}

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) Upd(A[j]), st.insert(A[j]);
			i = R[i];
			continue;
		}
		int lb = i, rb = R[i], j = i;
		if (A[i] >= *(--st.end())) {
			for (int j = i; j <= R[i]; ++j) Upd(A[j]), st.insert(A[j]);
			i = R[i];
			continue;
		}
		while (rb >= lb) {
			int md = (lb + rb) / 2;
			// can or not
			if (A[md] <= *st.begin()) {
				j = md;
				lb = md + 1;
				continue;
			}
			int l = *st.upper_bound(A[i]);
			int r = *(--st.lower_bound(A[md]));
			if (!Count(l, r)) {
				j = md;
				lb = md + 1;
			}else rb = md - 1;
		}
		i = j;
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 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 1 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 Incorrect 1 ms 364 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 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 1 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 Incorrect 1 ms 364 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 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 1 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 Incorrect 1 ms 364 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 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 1 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 Incorrect 1 ms 364 KB Output isn't correct
11 Halted 0 ms 0 KB -