B. The Best Gift
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Input

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 a1, a2, ..., an, where ai (1 ≤ ai ≤ 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.

Output

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.

Sample test(s)
input
4 3
2 1 3 1
output
5
input
7 4
4 2 3 1 2 4 3
output
18
Note

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.

记录每个种类的本数,然后两两相乘就好了

#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
int i,j;
int t;
int n,m;
int num;
map<__int64,__int64> q;
map<__int64,__int64>::iterator it;
map<__int64,__int64>::iterator itt;
int main()
{
__int64 sum=0;
cin>>n>>m;
for(i=0;i<n;i++)
{
cin>>num;
q[num]++;
}
for(it=q.begin();it!=q.end();it++)
{
for(itt=q.begin();itt!=q.end();itt++)
{
if(it->first!=itt->first)
{
sum+=(it->second)*(itt->second);
}
}
}
cout<<sum/2<<endl;
return 0;
}

  

Educational Codeforces Round 3 B的更多相关文章

  1. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  2. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  3. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  4. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  5. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

  6. Educational Codeforces Round 6 C. Pearls in a Row

    Educational Codeforces Round 6 C. Pearls in a Row 题意:一个3e5范围的序列:要你分成最多数量的子序列,其中子序列必须是只有两个数相同, 其余的数只能 ...

  7. Educational Codeforces Round 9

    Educational Codeforces Round 9 Longest Subsequence 题目描述:给出一个序列,从中抽出若干个数,使它们的公倍数小于等于\(m\),问最多能抽出多少个数, ...

  8. Educational Codeforces Round 37

    Educational Codeforces Round 37 这场有点炸,题目比较水,但只做了3题QAQ.还是实力不够啊! 写下题解算了--(写的比较粗糙,细节或者bug可以私聊2333) A. W ...

  9. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  10. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

随机推荐

  1. java中sleep()的用法

    Thread.sleep(long millis)和Thread.sleep(long millis, int nanos)静态方法强制当前正在执行的线程休眠(暂停执行),以“减慢线程”. 当线程睡眠 ...

  2. python爬虫(6)--Requests库的用法

    1.安装 利用pip来安装reques库,进入pip的下载位置,打开cmd,默认地址为 C:\Python27\Scripts 可以看到文件中有pip.exe,直接在上面输入cmd回车,进入命令行界面 ...

  3. iBase4J项目笔记

    目录: 1 数据库密码加密 2 service层概述 3 web层概述 4 后端CRUD 4.1 READ 4.2 UPDATE 4.3 CREATE 4.4 DELETE 5 facade层概述 1 ...

  4. SQL serve 数据库--视图、事物、分离附加、备份还原

    视图是数据库中的一种虚拟表,与真实的表一样,视图包含一系列带有名称的行和列数据.行和列数据用来自定义视图的查询所引用的表,并且在引用视图时动态生成.  视图只能用来查询,不能增删改:不允许出现重复列 ...

  5. Spring 框架学习 有用

    1.1.1 spring的优势 方便解耦,简化开发 通过Spring提供的IoC容器,可以将对象间的依赖关系交由Spring进行控制,避免硬编码所造成的过度程序耦合.用户也不必再为单例模式类.属性文件 ...

  6. GCD 学习(四) dispatch_group

    如果想在dispatch_queue中所有的任务执行完成后在做某种操作,在串行队列中,可以把该操作放到最后一个任务执行完成后继续,但是在并行队列中怎么做呢.这就有dispatch_group 成组操作 ...

  7. EZOJ #77

    传送门 分析 一个比较神奇的思路 我们考虑分治,对于每一个区间[le,ri]我们计算这个区间中左端点属于[le,mid],右端点属于[mid+1,ri]的情况对答案的贡献 我们求左半个区间的最大最小值 ...

  8. eclipse打包第三方jar的超简便方法

    原帖地址 http://wenku.baidu.com/link?url=0kCBUc-7g4pGgXUrBA2jdCRkrSQmQzaDgGT59TyECAundF8c6R9yxy4EaBN3L8c ...

  9. Installing the .NET Framework 3.5 on Windows 8, Windows 8.1 and Windows 10

    Installing the .NET Framework 3.5 on Windows 8, Windows 8.1 and Windows 10 .NET Framework (current v ...

  10. yum(Fedora和RedHat以及SUSE中的Shell前端软件包管理器)命令详解

    yum官方网站:http://yum.baseurl.org/ Fedora对于yum的介绍:http://fedoraproject.org/wiki/Yum yum(全称为 Yellow dog ...