PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000046. Đếm cặp nghịch thế nhân đôi (Reverse Pairs)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm cặp nghịch thế nhân đôi (Reverse Pairs)
Reverse Pairs
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer array , count index pairs with and . The comparison is strict; negatives and 32-bit boundary values are allowed.
Input
The first line is . The second line contains integers .
Output
Print the number of qualifying pairs.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5
1 3 2 3 1
Output
2
Explanation
The two valid pairs are positions (2,5) and (4,5), using 1-based indexing.