Submission #92523

# Submission time Handle Problem Language Result Execution time Memory
92523 2019-01-03T10:05:42 Z Nodir_Bobiev Money (IZhO17_money) C++14
0 / 100
2 ms 376 KB
// solved by using fenvick tree 
// + binary search

# include <iostream>

using namespace std;

const int N = 1e6 + 100;

int n, ans = 1;
int a[N];
int cnt[N];

void update(int i)
{
	while(i < N){
		cnt[i]++;
		i += (i & -i);
	}
}

int get(int i){
	int ret = 0;
	while(i > 0){
		ret += cnt[i];
		i -= (i & -i);
	}
	return ret;
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	
	update(1e6);
	update(a[1]);
	
	int x = 1e6;
	for (int i = 2; i <= n; i++){
		if(a[i] >= a[i - 1] && x >= a[i])
			update(a[i]);
		
		else{
			int l = a[i], r = 1e6, m;
			while(r > l){
				m = (l + r) >> 1;
				if(get(a[m]) > get(a[i]))
					r = m;
				else
					l = m + 1;
			}
			x = l;
			update(a[i]);
			++ans;
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -