CF1677A.Tokitsukaze and Strange Inequality

普及/提高-

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Tokitsukaze has a permutation pp of length nn. Recall that a permutation pp of length nn is a sequence p1,p2,…,pnp_1, p_2, \ldots, p_n consisting of nn distinct integers, each of which from 11 to nn (1≤pi≤n1 \leq p_i \leq n).

She wants to know how many different indices tuples [a,b,c,d][a,b,c,d] (1≤a<b<c<d≤n1 \leq a \lt b \lt c \lt d \leq n) in this permutation satisfy the following two inequalities:

pa<pcp_a \lt p_c and pb>pdp_b \gt p_d.

Note that two tuples [a1,b1,c1,d1][a_1,b_1,c_1,d_1] and [a2,b2,c2,d2][a_2,b_2,c_2,d_2] are considered to be different if a1≠a2a_1 \ne a_2 or b1≠b2b_1 \ne b_2 or c1≠c2c_1 \ne c_2 or d1≠d2d_1 \ne d_2.

Tokitsukaze 有一个长度为 nn 的排列 pp。回忆一下,长度为 nn 的排列 pp 是一个由 nn 个互不相同的整数组成的序列 p1,p2,…,pnp_1, p_2, \ldots, p_n,其中每个数均在 11 到 nn 之间(即 1≤pi≤n1 \leq p_i \leq n)。

她想知道,在该排列中,有多少个不同的下标四元组 [a,b,c,d][a,b,c,d](满足 1≤a<b<c<d≤n1 \leq a \lt b \lt c \lt d \leq n)使得以下两个不等式同时成立:

pa<pcp_a \lt p_c 且 pb>pdp_b \gt p_d。

注意:若两个四元组 [a1,b1,c1,d1][a_1,b_1,c_1,d_1] 与 [a2,b2,c2,d2][a_2,b_2,c_2,d_2] 满足 a1≠a2a_1 \ne a_2 或 b1≠b2b_1 \ne b_2 或 c1≠c2c_1 \ne c_2 或 d1≠d2d_1 \ne d_2,则它们被视为不同的四元组。

输入格式

The first line contains one integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. Each test case consists of two lines.

The first line contains a single integer nn (4≤n≤50004 \leq n \leq 5000) — the length of permutation pp.

The second line contains nn integers p1,p2,…,pnp_1, p_2, \ldots, p_n (1≤pi≤n1 \leq p_i \leq n) — the permutation pp.

It is guaranteed that the sum of nn over all test cases does not exceed 50005000.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。每个测试用例由两行组成。

第一行包含一个整数 nn(4≤n≤50004 \leq n \leq 5000),表示排列 pp 的长度。

第二行包含 nn 个整数 p1,p2,…,pnp_1, p_2, \ldots, p_n(1≤pi≤n1 \leq p_i \leq n),表示排列 pp。

保证所有测试用例的 nn 之和不超过 50005000。

输出格式

For each test case, print a single integer — the number of different [a,b,c,d][a,b,c,d] tuples.

对于每个测试用例,输出一个整数——不同的 [a,b,c,d][a,b,c,d] 元组的个数。

输入输出样例

  • 输入#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 33 different [a,b,c,d][a,b,c,d] tuples.

p1=5p_1 = 5, p2=3p_2 = 3, p3=6p_3 = 6, p4=1p_4 = 1, where p1<p3p_1 \lt p_3 and p2>p4p_2 \gt p_4 satisfies the inequality, so one of [a,b,c,d][a,b,c,d] tuples is [1,2,3,4][1,2,3,4].

Similarly, other two tuples are [1,2,3,6][1,2,3,6], [2,3,5,6][2,3,5,6].

在第一个测试用例中,共有 33 个不同的 [a,b,c,d][a,b,c,d] 元组。

p1=5p_1 = 5,p2=3p_2 = 3,p3=6p_3 = 6,p4=1p_4 = 1,其中 p1<p3p_1 \lt p_3 且 p2>p4p_2 \gt p_4 满足该不等式,因此其中一个 [a,b,c,d][a,b,c,d] 元组为 [1,2,3,4][1,2,3,4]。

类似地,另外两个元组分别为 [1,2,3,6][1,2,3,6] 和 [2,3,5,6][2,3,5,6]。

输入解题思路,AI测评打分。不知道怎么写?

首页