// Olimpíadas Nacionais de Informática 2020 // Treino #01: Problema C - Rebentando os Balões // Transcrição da solução oficial (convertida de C++ para Java) import java.util.Scanner; import java.util.TreeSet; import java.util.ArrayList; class c { static final int MAX = 10005; static ArrayList> S = new ArrayList<>(MAX); static int find (int pos, int v) { Integer it = S.get(v).ceiling(pos+1); if (it == null) return -1; return it; } public static void main(String[] args) { for (int i=0; i()); Scanner in = new Scanner(System.in); int n = in.nextInt(); int v[] = new int[n]; for (int i = 0; i < n; ++i) { v[i] = in.nextInt(); S.get(v[i]).add(i); } int ans = 0; for (int i = 0; i < n; ++i) { if (!S.get(v[i]).contains(i)) continue; int pos = i; ++ans; while (pos >= 0) { S.get(v[pos]).remove(pos); pos = find(pos, v[pos] - 1); } } System.out.println(ans); } }