You could do it in O(n):
public int solution(int[] a) {
Set missing = new HashSet<>();
Set store = new HashSet<>();
int count = 0;
for (int i = 0; i < a.length; i++) {
if (!store.contains(i + 1) && i + 1 != a[i])
missing.add(i + 1);
if (i + 1 < a[i])
store.add(a[i]);
else
missing.remove(a[i]);
if (missing.isEmpty())
count++;
}
return count;
}