CF2201A1 Lost Civilization (Easy Version)

import java.util.Scanner;
import java.util.Stack;


public class App {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int cases = Integer.parseInt(sc.nextLine());
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < cases; ++i) {
            int cnt = sc.nextInt();
            int[] arr = new int[cnt];
            for (int j = 0; j < cnt; ++j)  {
                int n = sc.nextInt();
                arr[cnt - j - 1] = n;
            }
            for (int k : arr) {
                if (stack.isEmpty()) stack.push(k);
                else {
                    while (!stack.isEmpty() && stack.peek() == k + 1) stack.pop();
                    stack.push(k);
                }
            }
            System.out.println(stack.size());
            stack.clear();      
        }
        sc.close();
    }
}
posted @ 2026-04-01 14:15  kayaker  阅读(6)  评论(0)    收藏  举报