PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000018. Đếm bộ ba giữ nguyên thứ tự trong hai hoán vị (Count Good Triplets in an Array)
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 bộ ba giữ nguyên thứ tự trong hai hoán vị (Count Good Triplets in an Array)
Count Good Triplets in an Array
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
You are given two permutations and of . Choose three distinct values . The triple is good if occurs before and before in both permutations. Count all good triples. This concerns positions, not numeric ordering of the chosen values.
Input
The first line contains . The second contains permutation . The third contains permutation . Each is a permutation of .
Output
Print one 64-bit integer: the number of triples of values appearing in the same order in both permutations.
Subtasks
- Subtask 1 (20 points): ; each of and is a permutation of .
- Subtask 2 (30 points): ; each of and is a permutation of .
- Subtask 3 (50 points): ; each of and is a permutation of .
Examples
Input
4
2 0 1 3
0 1 2 3
Output
1
Explanation
The first permutation has four ordered triples: , , , and . Only appears in that same order in the second permutation. The answer is .