#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, a[1000005], p[1000005];
int find(int v) {
if (p[v] == v) return v;
return p[v] = find(p[v]);
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
p[i] = i;
}
int ans = 0; int c = 0, j = n;
while (j >= 1) {
if (c == 0 || c != a[j]) ans++;
c = find(a[j] - 1);
p[a[j]] = c;
j--;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |