D - Distinct Trio
Editorial
/


Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 400 点
問題文
長さ N の数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
以下の 2 条件をともに満たすような整数の組 (i,j,k) の個数を求めてください。
- 1\leq i \lt j \lt k \leq N
- A_i,A_j,A_k は相異なる
制約
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 2\times 10^5
- 入力に含まれる値は全て整数である
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
答えを出力せよ。
入力例 1
4 3 1 4 1
出力例 1
2
条件を満たす整数の組 (i,j,k) は (1,2,3),(1,3,4) の 2 つです。
入力例 2
10 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990
出力例 2
120
入力例 3
15 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
出力例 3
355
Score : 400 points
Problem Statement
You are given a sequence of length N: A=(A_1,A_2,\ldots,A_N).
Find the number of triples (i,j,k) that satisfy both of the following conditions.
- 1\leq i \lt j \lt k \leq N
- A_i, A_j, and A_k are distinct.
Constraints
- 3 \leq N \leq 2\times 10^5
- 1 \leq A_i \leq 2\times 10^5
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
Print the answer.
Sample Input 1
4 3 1 4 1
Sample Output 1
2
The two triples (i,j,k) satisfying the conditions are (1,2,3) and (1,3,4).
Sample Input 2
10 99999 99998 99997 99996 99995 99994 99993 99992 99991 99990
Sample Output 2
120
Sample Input 3
15 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9
Sample Output 3
355