aboutsummaryrefslogtreecommitdiff
path: root/02_sorting_and_searching/collecting_numbers_2216.cpp
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-07-06 19:08:08 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2026-07-06 19:08:08 +0200
commit96254947699986c59f0dc63d69fd4b76bd3ed43e (patch)
tree6c4dca945d7f7427c48be234d827fe4d33be02c5 /02_sorting_and_searching/collecting_numbers_2216.cpp
downloadcses-96254947699986c59f0dc63d69fd4b76bd3ed43e.tar.gz
cses-96254947699986c59f0dc63d69fd4b76bd3ed43e.zip
Initial commit
Diffstat (limited to '02_sorting_and_searching/collecting_numbers_2216.cpp')
-rw-r--r--02_sorting_and_searching/collecting_numbers_2216.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/02_sorting_and_searching/collecting_numbers_2216.cpp b/02_sorting_and_searching/collecting_numbers_2216.cpp
new file mode 100644
index 0000000..1adcf28
--- /dev/null
+++ b/02_sorting_and_searching/collecting_numbers_2216.cpp
@@ -0,0 +1,46 @@
1#include <iostream>
2#include <vector>
3
4int main() {
5 size_t n, x, s{1}, l{0};
6 std::cin >> n;
7 std::vector<size_t> b(n);
8 for (size_t i = 0; i < n; i++) {
9 std::cin >> x;
10 b[x-1] = i;
11 }
12 for (size_t i = 0; i < n; i++) {
13 s += b[i] < l;
14 l = b[i];
15 }
16 std::cout << s << "\n";
17}
18
19
20// The code below solves a different problem: it finds the minimum number
21// of ascending chains needed to partition the given list of numbers.
22
23#if 0
24
25#include <algorithm>
26#include <iostream>
27#include <vector>
28
29int main() {
30 size_t n;
31 std::vector<size_t> s;
32 std::cin >> n;
33 for (size_t i = 0; i < n; i++) {
34 size_t x;
35 std::cin >> x;
36 auto it = std::lower_bound(
37 s.begin(), s.end(), x, std::greater<size_t>());
38 if (it != s.end())
39 *it = x;
40 else
41 s.push_back(x);
42 }
43 std::cout << s.size() << std::endl;
44}
45
46#endif

Generated with cgit - Back to sebastiano.tronto.net