Codeforces Round #261 (Div. 2) D. Pashmak and Parmida
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 con
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 a1,?a2,?...,?an. Let's denotef(l,?r,?x) the number of indicesk such that: l?≤?k?≤?r andak?=?x. His task is to calculate the number of pairs of indiciesi,?j (1?≤?i?j?≤?n) such thatf(1,?i,?ai)?>?f(j,?n,?aj).
Help Pashmak with the test.
Input
The first line of the input contains an integer n(1?≤?n?≤?106). The second line containsn space-separated integers a1,?a2,?...,?an(1?≤?ai?≤?109).
Output
Print a single integer — the answer to the problem.
Sample test(s)
Input
7 1 2 1 1 2 2 1
Output
8
Input
3 1 1 1
Output
1
Input
5 1 2 3 4 5
Output
0
由于原数过大,可使用map 映射,就不需要离散化了~两个数组,一个记录前面与本数相等的数的个数,一个记录后面与本数相等的数的个数~
题目便转化成求逆序数对,树状数组。答案long long
CODE:
#include#include #include #include #include #include #include #include #include #include #include
上一篇: php 的 FizzBuzzWhizz
推荐阅读
-
Educational Codeforces Round 97 (Rated for Div. 2) D. Minimal Height Tree
-
Codeforces Round #665 (Div. 2) D. Maximum Distributed Tree(dfs)
-
Codeforces Round #619 (Div. 2) D. Time to Run
-
Codeforces Round #583 (Div. 1 + Div. 2,) D. Treasure Island(dfs+思维)
-
Codeforces Round #533 (Div. 2) D. Kilani and the Game(bfs+模拟)
-
Codeforces Round #643 (Div. 2) D. Game With Array
-
Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)
-
Codeforces Round #260 (Div. 2) D. A Lot of Games(树上博弈)
-
Codeforces Round #662 (Div. 2) D. Rarity and New Dress
-
Codeforces Round #658 (Div. 2) D. Unmerge(dp,01背包)