#FT0000059. Đếm cặp nghịch thế (Inversion Pairs)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đếm cặp nghịch thế (Inversion Pairs)
Inversion Pairs
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
Tom and Jerry compete to count pairs of numbers according to a special rule. Given a sequence of positive integers , positions are numbered from left to right starting at .
An inversion is a pair of positions satisfying both and . Equal values do not form an inversion even when they occur at different positions.
Determine the total number of such position pairs, counting each pair exactly once.
Input
The first line contains the integer , the sequence length.
The second line contains exactly positive integers in positional order.
Output
Print one integer: the inversion count of the sequence.
Subtasks
-
Subtask 1 (25 points): ; for every element.
-
Subtask 2 (25 points): ; for every element.
-
Subtask 3 (50 points): ; for every element.
Examples
Input
6
5 4 2 6 3 1
Output
11
Explanation
For , count later values smaller than each value:
- The first value exceeds : pairs.
- The second value exceeds : pairs.
- The third value exceeds : pair.
- The fourth value exceeds : pairs.
- The fifth value exceeds : pair.
- The last value contributes .
Thus the answer is .