aboutsummaryrefslogtreecommitdiff
path: root/02_sorting_and_searching/collecting_numbers_2216.cpp
blob: 1adcf281e262d724a03720dfb4920eda0ce37876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <vector>

int main() {
	size_t n, x, s{1}, l{0};
	std::cin >> n;
	std::vector<size_t> b(n);
	for (size_t i = 0; i < n; i++) {
		std::cin >> x;
		b[x-1] = i;
	}
	for (size_t i = 0; i < n; i++) {
		s += b[i] < l;
		l = b[i];
	}
	std::cout << s << "\n";
}


// The code below solves a different problem: it finds the minimum number
// of ascending chains needed to partition the given list of numbers.

#if 0

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
	size_t n;
	std::vector<size_t> s;
	std::cin >> n;
	for (size_t i = 0; i < n; i++) {
		size_t x;
		std::cin >> x;
		auto it = std::lower_bound(
		    s.begin(), s.end(), x, std::greater<size_t>());
		if (it != s.end())
			*it = x;
		else
			s.push_back(x);
	}
	std::cout << s.size() << std::endl;
}

#endif

Generated with cgit - Back to sebastiano.tronto.net