CSES Solutions
#2216Sorting and Searching

Collecting Numbers

View on CSES

Solution

2216-Collecting_Numbers.cpp
1#include<bits/stdc++.h>
2using namespace std;
3#define int long long
4signed main(){
5  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
6  int n; cin>>n;
7  int p[n],ans=1; for(int i=0,x;i<n;++i)
8    cin>>x,p[--x]=i;
9  for(int i=1;i<n;++i)
10    if(p[i]<p[i-1]) ++ans;
11  cout<<ans<<'\n';
12  return 0;
13}

Editorial not yet generated for this problem. Run the editorial generation script to add hints and detailed explanations.