102062: [AtCoder]ABC206 C - Swappable

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $300$ points

Problem Statement

Given an array of $N$ integers $A=(A_1,A_2,...,A_N)$, find the number of pairs $(i,j)$ of integers satisfying all of the following conditions:

  • $1 \le i < j \le N$
  • $A_i \neq A_j$

Constraints

  • All values in input are integers.
  • $2 \le N \le 3 \times 10^5$
  • $1 \le A_i \le 10^9$

Input

Input is given from Standard Input in the following format:

$N$
$A_1$ $A_2$ $\dots$ $A_N$

Output

Print the answer as an integer.


Sample Input 1

3
1 7 1

Sample Output 1

2

In this input, we have $A=(1,7,1)$.

  • For the pair $(1,2)$, $A_1 \neq A_2$.
  • For the pair $(1,3)$, $A_1 = A_3$.
  • For the pair $(2,3)$, $A_2 \neq A_3$.

Sample Input 2

10
1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000

Sample Output 2

45

Sample Input 3

20
7 8 1 1 4 9 9 6 8 2 4 1 1 9 5 5 5 3 6 4

Sample Output 3

173

Input

题意翻译

# 题目描述 给你一个数字 $n$,再给出这 $n$ 个数,用 $a_1 \sim a_n$ 代表这 $n$ 个数字的值,问这些数字中有多少对数,满足 $1 \leq i < j \leq n$ 并且 $ a_i \neq a_j $。 # 输入格式 第一行一个整数 $n$,第二行 $n$ 个整数代表 $a_1 \sim a_n$。 # 输出格式 输出一个整数为答案 # 数据范围 $N \leq 3\times10^5,Ai \leq 10^9$

加入题单

算法标签: