CF1677A.Tokitsukaze and Strange Inequality
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Tokitsukaze has a permutation p of length n . Recall that a permutation p of length n is a sequence p1,p2,…,pn consisting of n distinct integers, each of which from 1 to n ( 1≤pi≤n ).
She wants to know how many different indices tuples [a,b,c,d] ( 1≤a<b<c<d≤n ) in this permutation satisfy the following two inequalities:
pa<pc and pb>pd . Note that two tuples [a1,b1,c1,d1] and [a2,b2,c2,d2] are considered to be different if a1=a2 or b1=b2 or c1=c2 or d1=d2 .
输入格式
The first line contains one integer t ( 1≤t≤1000 ) — the number of test cases. Each test case consists of two lines.
The first line contains a single integer n ( 4≤n≤5000 ) — the length of permutation p .
The second line contains n integers p1,p2,…,pn ( 1≤pi≤n ) — the permutation p .
It is guaranteed that the sum of n over all test cases does not exceed 5000 .
输出格式
For each test case, print a single integer — the number of different [a,b,c,d] tuples.
输入输出样例
输入#1
3 6 5 3 6 1 4 2 4 1 2 3 4 10 5 1 6 2 8 3 4 10 9 7
输出#1
3 0 28
说明/提示
In the first test case, there are 3 different [a,b,c,d] tuples.
p1=5 , p2=3 , p3=6 , p4=1 , where p1<p3 and p2>p4 satisfies the inequality, so one of [a,b,c,d] tuples is [1,2,3,4] .
Similarly, other two tuples are [1,2,3,6] , [2,3,5,6] .