PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000013. Đếm cặp nghịch thế (INVCNT - Inversion Count)
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 cặp nghịch thế (INVCNT - Inversion Count)
INVCNT - Inversion Count
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are given pairwise distinct positive integers. An inversion is a pair of positions for which . Count all inversions, including those formed by non-adjacent elements.
Input
The first line contains the integer . The next line contains positive integers in their original order.
Output
Print one integer: the total number of inversions.
Subtasks
- Subtask 1 (20 points): ; for every ; all are pairwise distinct.
- Subtask 2 (30 points): ; for every ; all are pairwise distinct.
- Subtask 3 (50 points): ; for every ; all are pairwise distinct.
Examples
Input
5
2 3 8 6 1
Output
5
Explanation
The five inversions are the value pairs , , , , and , at position pairs , , , , and . No other pair has its first element greater than its second, so the answer is .