2176A - Operations with Inversions


public class App {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < n; ++i) {
            int cnt = sc.nextInt();
            int[] arr = new int[cnt];
            for (int j = 0; j < cnt; ++j)  {
                arr[j] = sc.nextInt();
            }
            int ans = 0;
            for (int pos1 = 0; pos1 < cnt; ++pos1) {
                if (arr[pos1] == -1) continue;
                for (int pos2 = pos1 + 1; pos2 < cnt; ++pos2) {
                    if (arr[pos1] > arr[pos2] && arr[pos2] != -1) {
                        ++ans;
                        arr[pos2] = -1;
                    }
                }
            }
            System.out.println(ans);
        }
        sc.close();
    }
}
posted @ 2026-01-19 17:00  kayaker  阅读(1)  评论(0)    收藏  举报