Submission #36872

# Submission time Handle Problem Language Result Execution time Memory
36872 2017-12-16T21:48:21 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;
			}

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

	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Correct 0 ms 9988 KB Output is correct
3 Correct 0 ms 9988 KB Output is correct
4 Correct 0 ms 9988 KB Output is correct
5 Incorrect 0 ms 9988 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Correct 0 ms 9988 KB Output is correct
3 Correct 0 ms 9988 KB Output is correct
4 Correct 0 ms 9988 KB Output is correct
5 Incorrect 0 ms 9988 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Correct 0 ms 9988 KB Output is correct
3 Correct 0 ms 9988 KB Output is correct
4 Correct 0 ms 9988 KB Output is correct
5 Incorrect 0 ms 9988 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 9988 KB Output is correct
2 Correct 0 ms 9988 KB Output is correct
3 Correct 0 ms 9988 KB Output is correct
4 Correct 0 ms 9988 KB Output is correct
5 Incorrect 0 ms 9988 KB Output isn't correct
6 Halted 0 ms 0 KB -