PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000026. Đếm nghịch thế khi thay đổi phần tử (Inversion Counting)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm nghịch thế khi thay đổi phần tử (Inversion Counting)
Inversion Counting
Source: VNOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given positive integers . Process assignments , each setting . Immediately after each assignment, output the number of inversions with and across the entire current array. Equal values do not form inversions.
Input
The first line is , followed by initial values. The third line contains . Each of the next lines gives .
Output
Print exactly lines, with the inversion count after assignment on line .
Subtasks
- Subtask 1 (10 points): ; ; ; . Reassigning the same value and duplicates are allowed.
- Subtask 2 (20 points): ; ; ; . Reassigning the same value and duplicates are allowed.
- Subtask 3 (30 points): ; ; ; . Reassigning the same value and duplicates are allowed.
- Subtask 4 (40 points): ; ; ; . Reassigning the same value and duplicates are allowed.
Examples
Input
10
2 6 6 4 7 6 3 5 9 1
7
8 8
5 1
5 6
10 5
7 1
10 10
4 6
Output
17
18
16
13
14
8
6
Explanation
The example contains values and assignments. After the first assignment 8 8, the array has inversions. The subsequent inversion totals are , always measured after the current assignment.