Educational Codeforces Round 94 (Rated for Div. 2) D(思维)
題目:
You are given an array a1,a2…an. Calculate the number of tuples (i,j,k,l) such that:
1≤i<j<k<l≤n;
ai=ak and aj=al;
Input
The first line contains a single integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains a single integer n (4≤n≤3000) — the size of the array a.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n) — the array a.
It’s guaranteed that the sum of n in one test doesn’t exceed 3000.
Output
For each test case, print the number of described tuples.
Example
inputCopy
2
5
2 2 2 2 2
6
1 3 3 1 2 3
outputCopy
5
2
Note
In the first test case, for any four indices i<j<k<l are valid, so the answer is the number of tuples.
In the second test case, there are 2 valid tuples:
(1,2,4,6): a1=a4 and a2=a6;
(1,3,4,6): a1=a4 and a3=a6.
題目大意: 找到滿足條件的所有組合
1≤i<j<k<l≤n;
ai=ak and aj=al;
思路 :枚舉j和l,然后用num來統(tǒng)計 j到l 有多少種組合。
cnt數(shù)組 記錄好 j下標(biāo)前面 出現(xiàn)過多少次這個數(shù)。
因為數(shù)據(jù)比較小,直接o(n^2).
總結(jié)
以上是生活随笔為你收集整理的Educational Codeforces Round 94 (Rated for Div. 2) D(思维)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一键拆卸自由升级的高性能电竞主机,戴尔X
- 下一篇: 可大幅提高内存的运行效率可大幅提高内存的