#FT0000217. Số nghịch thế khi xóa động (Dynamic Inversions)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Số nghịch thế khi xóa động (Dynamic Inversions)
Dynamic Inversions
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a permutation containing each integer from to exactly once.
An inversion of the current array is a pair of positions with and . Positions refer to the remaining sequence after previous removals, without gaps.
You will remove elements in a prescribed order, specified by their values. Each value is deleted at most once. Removing a value preserves the relative order of the remaining elements.
Before each removal, print the number of inversions in the current array. Inversions involving the element about to be removed must still be counted, because the removal has not yet happened.
Input
- The first line contains integers : the initial permutation size and the number of deletions.
- The following lines each contain one integer : the value originally located at position .
- The following lines each contain one integer : the value removed at deletion step . All values are distinct and occur in the original permutation.
Output
Print exactly lines. Line contains the number of inversions immediately before deleting value . The answer may exceed the range of a -bit integer.
Subtasks
- Subtask 1 (20 points): ; ; is a permutation of ; are distinct and all belong to .
- Subtask 2 (30 points): ; ; is a permutation of ; are distinct and all belong to .
- Subtask 3 (50 points): ; ; is a permutation of ; are distinct and all belong to .
Examples
Input
5 4
1
5
3
4
2
5
1
4
2
Output
5
2
2
1
Explanation
The initial permutation is . Answers are computed before performing their deletions:
- Before removing , the five inversions are , , , , . Print
5; the remaining array becomes . - Before removing , has inversions and . Print
2; the array becomes . - Before removing , has those same two inversions. Print
2; the array becomes . - Before removing , has exactly one inversion . Print
1.
Thus the four lines are 5, 2, 2, and 1.