PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000024. Tổng vị trí sau khi ghép hai tập (Merge Sets)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng vị trí sau khi ghép hai tập (Merge Sets)
Merge Sets
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are integer sets , each with exactly elements. All elements across all sets are distinct. For two sets , merge their elements and sort them increasingly into sequence . Define as the sum of 1-based positions of elements from in . Find .
Input
The first line contains integers . Each of the following lines contains the elements of set . Elements within a line need not be sorted.
Output
Print one 64-bit integer: the total .
Subtasks
- Subtask 1 (20 points): ; ; for all ; all across all sets are pairwise distinct.
- Subtask 2 (30 points): ; ; for all ; all across all sets are pairwise distinct.
- Subtask 3 (50 points): ; ; for all ; all across all sets are pairwise distinct.
Examples
Input
3 2
1 3
2 8
4 6
Output
12
Explanation
For , the merged sorted values are ; the first set occupies positions and , contributing . For , the sorted values are and the contribution is . For , positions and contribute . The total is .