Collecting Numbers - Problem link
#include <iostream> #include <set> #include <map> #include <vector> #include <stack> #include <queue> #include <utility> #include <unordered_set> #include <unordered_map> #include <cmath> #include <climits> #include <cinttypes> #include <algorithm> using namespace std; typedef long long ll; typedef long int longi; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpii; template <class T> int size(const T &x) { return x.size(); } const int INF = 2147483647; #define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i) #define iter(it,c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n + 1); rep(i, 1, n + 1) { int temp; cin >> temp; a[temp] = i; } int count = 1, prev = 0; rep(i, 1, n + 1) { if (a[i] < prev) count++; prev = a[i]; } cout << count << endl; return 0; } 