PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FT0000090. Nghịch thế bộ ba (Mega Inversions)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Nghịch thế bộ ba (Mega Inversions)
Mega Inversions
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Given a sequence of positive integers , a mega inversion is a triple of positions whose values are strictly decreasing:
Equal values may occur but never satisfy a strict comparison. Triples are distinguished by their chosen positions. Count all mega inversions; the answer may require a 64-bit integer.
Input
The first line contains the integer .
The second line contains exactly integers .
Output
Print one integer: the number of triples with .
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
4
3 3 2 1
Output
2
Explanation
The sequence is . Exactly two decreasing triples exist: indices and . Both yield the values .
Any triple containing both occurrences of fails because is false. Therefore the output is 2.