답안 #344848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
344848 2021-01-06T16:14:23 Z dimashii Money (IZhO17_money) C++17
0 / 100
0 ms 364 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 nxt = l;
		if (st.upper_bound(l) != st.end()) l = *st.upper_bound(l);
		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;
			}
			if (A[md] <= l) {
				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;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:33:7: warning: unused variable 'nxt' [-Wunused-variable]
   33 |   int nxt = l;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 0 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -