답안 #36873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36873 2017-12-16T21:50:13 Z JustInCase Money (IZhO17_money) C++14
0 / 100
0 ms 9988 KB
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

const int MAX_N = 1e6 + 5;
const int MAX_A = 1e6 + 5;

struct IndexTree {
	private:
		int data[MAX_A];
	
	public:
		void Add(int ind, int val);
		int Get(int ind);
		int GetInInterval(int low, int high);
};

void IndexTree::Add(int ind, int val) {
	while(ind < MAX_A) {
		data[ind] += val;
		ind += (ind & (-ind));
	}
}

int IndexTree::Get(int ind) {
	int ans = 0;
	while(ind > 0) {
		ans += data[ind];
		ind -= (ind & (-ind));
	}
	return ans;
}

int IndexTree::GetInInterval(int low, int high) {
	return Get(high) - Get(low - 1);
}

int a[MAX_N];
IndexTree indexTree;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	int n;
	cin >> n;

	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	
	int ans = 0;
	for(int i = 0; i < n; ) {
		int j;
		for(j = i + 1; j < n; j++) {
			if(a[j] < a[j - 1] || indexTree.GetInInterval(a[i] + 1, a[j] - 1) > 0) {
				break;
			}
		}
		
		ans++;
		i = j;

		for(j = i; j < i; j++) {
			indexTree.Add(a[j], 1);
		}
	}

	cout << ans << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Incorrect 0 ms 9988 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Incorrect 0 ms 9988 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Incorrect 0 ms 9988 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Incorrect 0 ms 9988 KB Output isn't correct
3 Halted 0 ms 0 KB -