302386: CF459D. Pashmak and Parmida's problem

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

Description

Pashmak and Parmida's problem

题意翻译

- 给出长度为 $n(1\le n\le10^6)$ 的序列 $a(1\le a_i\le10^9)$。 - $f(i,j,x)$ 表示 $a_i\dots a_j$ 中 $x$ 的出现次数。 - 求有多少对 $i,j$ 满足 $f(1,i,a_i) > f(j,n,a_j)$ 且 $i < j$。

题目描述

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&lt;j<=n) $ such that $ f(1,i,a_{i})&gt;f(j,n,a_{j}) $ . Help Pashmak with the test.

输入输出格式

输入格式


The first line of the input contains an integer $ n $ $ (1<=n<=10^{6}) $ . The second line contains $ n $ space-separated integers $ a_{1},a_{2},...,a_{n} $ $ (1<=a_{i}<=10^{9}) $ .

输出格式


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

Input

题意翻译

- 给出长度为 $n(1\le n\le10^6)$ 的序列 $a(1\le a_i\le10^9)$。 - $f(i,j,x)$ 表示 $a_i\dots a_j$ 中 $x$ 的出现次数。 - 求有多少对 $i,j$ 满足 $f(1,i,a_i) > f(j,n,a_j)$ 且 $i < j$。

加入题单

上一题 下一题 算法标签: