CF459D.Pashmak and Parmida's problem

普及/提高-

通过率:0%

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 aa that consists of nn integers a1,a2,...,ana_{1},a_{2},...,a_{n} . Let's denote f(l,r,x)f(l,r,x) the number of indices kk such that: l<=k<=rl<=k<=r and ak=xa_{k}=x . His task is to calculate the number of pairs of indicies i,ji,j (1<=i<j<=n) such that f(1,i,a_{i})>f(j,n,a_{j}) .

Help Pashmak with the test.
帕米达是个聪明的女孩,今年她想参加奥林匹克竞赛。当然,她希望她的搭档也很聪明(虽然他并不聪明)!帕尔米达为帕什马克准备了以下测试题。

有一个序列 a 由 n 个整数a1,a2,...,ana_{1},a_{2},...,a_{n}组成。让我们用 f(l,r,x)f(l,r,x) 表示这样的索引 k 的个数: l<=k<=rl<=k<=rak=xa_{k}=x 。他的任务是计算 i, j 和 i,ji,j (1<=i<j<=n)(1<=i \lt j<=n)这两个索引的对数。 (1<=i<j<=n)(1<=i \lt j<=n)f(1,i,ai)>f(j,n,aj)f(1,i,a_{i}) \gt f (j,n,a_{j}) 的个数。

帮助 Pashmak 完成测试。

输入格式

The first line of the input contains an integer nn (1<=n<=106)(1<=n<=10^{6}) . The second line contains nn space-separated integers a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=109)(1<=a_{i}<=10^{9}) .
输入
输入的第一行包含一个整数 nn (1<=n<=106)(1<=n<=10^{6}) .第二行包含 n 个空格分隔的整数 a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=109)(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
    
首页