CF459D.Pashmak and Parmida's problem
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Parmida is a clever girl and she wants to participate in Olympiads this year. Of course she wants her partner to be clever too (although he's not)! Parmida has prepared the following test problem for Pashmak.
There is a sequence a that consists of n integers _a_1, _a_2, ..., a__n. Let's denote f(l, r, x) the number of indices k such that: l ≤ k ≤ r and a__k = x. His task is to calculate the number of pairs of indicies i, j (1 ≤ i < j ≤ n) such that f(1, i, a__i) > f(j, n, a__j).
Help Pashmak with the test.
帕尔米达是一个聪明的女孩,她今年想参加奥林匹克竞赛。当然,她也希望自己的搭档同样聪明(尽管他其实并不聪明)!帕尔米达为帕什马克准备了如下测试题。
给定一个由 n 个整数 a1, a2, ..., an 组成的序列 a。定义函数 f(l, r, x) 表示满足 l ≤ k ≤ r 且 ak = x 的下标 k 的个数。他的任务是计算满足如下条件的下标对 (i, j)(其中 1 ≤ i < j ≤ n)的个数:
f(1, i, ai) > f(j, n, aj).
请帮助帕什马克解决这道测试题。
输入格式
The first line of the input contains an integer n (1 ≤ n ≤ 106). The second line contains n space-separated integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109).
输入的第一行包含一个整数 n(1≤n≤106)。第二行包含 n 个以空格分隔的整数 a1, a2, …, an(1≤ai≤109)。
输出格式
Print a single integer — the answer to the problem.
输出一个整数——该问题的答案。
输入输出样例
输入#1
7 1 2 1 1 2 2 1
输出#1
8
输入#2
3 1 1 1
输出#2
1
输入#3
5 1 2 3 4 5
输出#3
0
输入解题思路,AI测评打分。不知道怎么写?