CF609B.The Best Gift

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are n books on sale from one of m genres.

In the bookshop, Jack decides to buy two books of different genres.

Based on the genre of books on sale in the shop, find the number of options available to Jack for choosing two books of different genres for Emily. Options are considered different if they differ in at least one book.

The books are given by indices of their genres. The genres are numbered from 1 to m.

艾米莉的生日在下周,杰克决定为她买一份礼物。他知道艾米莉喜欢读书,于是前往当地书店,那里正在销售 nn 本书,这些书来自 mm 种不同的类型。

在书店中,杰克决定购买两本类型不同的书。

根据书店中正在销售的书籍的类型分布,请计算杰克为艾米莉挑选两本不同类型书籍的方案数。若两个方案中至少有一本书不同,则视为不同的方案。

每本书由其所属类型的编号表示。类型编号从 11 到 mm。

输入格式

The first line contains two positive integers n and m (2 ≤ n ≤ 2·105, 2 ≤ m ≤ 10) — the number of books in the bookstore and the number of genres.

The second line contains a sequence _a_1, _a_2, ..., a__n, where a__i (1 ≤ a__i ≤ m) equals the genre of the i-th book.

It is guaranteed that for each genre there is at least one book of that genre.

第一行包含两个正整数 nn 和 mm(2 ≤ n ≤ 2⋅1052 \leq n \leq 2\cdot10^5,2 ≤ m ≤ 102 \leq m \leq 10)—— 分别表示书店中图书的总数以及图书种类(即题材类别)的总数。

第二行包含一个序列 a1, a2, ..., ana_1, a_2, ..., a_n,其中 aia_i(1 ≤ ai ≤ m1 \leq a_i \leq m)表示第 ii 本书所属的题材类别。

保证每种题材类别至少有一本对应的图书。

输出格式

Print the only integer — the number of ways in which Jack can choose books.

It is guaranteed that the answer doesn't exceed the value 2·109.

输出唯一的整数——Jack 选择书籍的方法数。

保证答案不超过 2⋅1092 \cdot 10^9。

输入输出样例

  • 输入#1

    4 3
    2 1 3 1

    输出#1

    5
  • 输入#2

    7 4
    4 2 3 1 2 4 3

    输出#2

    18

说明/提示

The answer to the first test sample equals 5 as Sasha can choose:

  1. the first and second books,
  2. the first and third books,
  3. the first and fourth books,
  4. the second and third books,
  5. the third and fourth books.

第一个测试样例的答案为 5,因为萨沙可以选择:

  1. 第一本书和第二本书,
  2. 第一本书和第三本书,
  3. 第一本书和第四本书,
  4. 第二本书和第三本书,
  5. 第三本书和第四本书。

输入解题思路,AI测评打分。不知道怎么写?

首页