commit 31d25e3b8218bc424519e602fc03efef1aa6760d parent 28ffabcb2a8daab7a39fdf887afc3d42a45c8b21 Author: superpozycja <anna@superpozycja.net> Date: Tue, 29 Oct 2024 11:08:26 +0100 solve collecting numbers 1 Diffstat:
A | sorting_and_searching/collecting_numbers.cpp | | | 43 | +++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 43 insertions(+), 0 deletions(-)
diff --git a/sorting_and_searching/collecting_numbers.cpp b/sorting_and_searching/collecting_numbers.cpp @@ -0,0 +1,43 @@ +#include <bits/stdc++.h> + +using namespace std; + +using ui = unsigned int; +using l = long; +using ul = unsigned long; +using ll = long long; +using ull = unsigned long long; + +using vi = vector<int>; +using vui = vector<ui>; +using vl = vector<l>; +using vul = vector<ul>; +using vll = vector<ll>; +using vull = vector<ull>; + +void solve() +{ + int n; + cin >> n; + vector<pair<int, int>> x; + for (int i = 0; i < n; i++) { + int tmp; + cin >> tmp; + x.push_back({tmp, i}); + + }; + int res = 1; + sort(x.begin(), x.end()); + for (int i = 0; i < n-1; i++) { + if (x[i].second > x[i+1].second) + res++; + } + cout << res << "\n"; +} + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + solve(); +}