MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / main

Function main

CSES/Sorting/CollectionNumbers.cc:5–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3using namespace::std;
4
5signed main(){
6 ios_base::sync_with_stdio(false),cin.tie(nullptr);
7
8 int n; cin >> n;
9 std::vector<int> v(n);
10 map<int,int>m;
11 int ans = 1;
12 for (int &x: v) cin >> x, --x;
13 for (int i = 0; i < n; ++i) { m[v[i]] = i; }
14 for (int i = 1; i < n; ++i) {
15 ans += (m[i] < m[i-1]);
16 }
17 cout << ans << endl;
18 return 0;
19}
20
21// main observation is
22// if a number x come before x + 1 then no extra move required but otherwise we need extra move

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected