CF1400D.Zigzags

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array a1,a2…ana_1, a_2 \dots a_n. Calculate the number of tuples (i,j,k,l)(i, j, k, l) such that:

  • 1≤i<j<k<l≤n1 \le i \lt j \lt k \lt l \le n;
  • ai=aka_i = a_k and aj=ala_j = a_l;

给你一个数组 a1,a2…ana_1, a_2 \dots a_n。请计算满足以下条件的四元组 (i,j,k,l)(i, j, k, l) 的个数:

  • 1≤i<j<k<l≤n1 \le i \lt j \lt k \lt l \le n;
  • ai=aka_i = a_k 且 aj=ala_j = a_l;

输入格式

The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases.

The first line of each test case contains a single integer nn (4≤n≤30004 \le n \le 3000) — the size of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤n1 \le a_i \le n) — the array aa.

It's guaranteed that the sum of nn in one test doesn't exceed 30003000.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(4≤n≤30004 \le n \le 3000)—— 数组 aa 的大小。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤n1 \le a_i \le n)—— 数组 aa。

保证单个测试用例中所有 nn 的总和不超过 30003000。

输出格式

For each test case, print the number of described tuples.

对于每个测试用例,输出满足描述的元组个数。

输入输出样例

  • 输入#1

    2
    5
    2 2 2 2 2
    6
    1 3 3 1 2 3

    输出#1

    5
    2

说明/提示

In the first test case, for any four indices i<j<k<li \lt j \lt k \lt l are valid, so the answer is the number of tuples.

In the second test case, there are 22 valid tuples:

  • (1,2,4,6)(1, 2, 4, 6): a1=a4a_1 = a_4 and a2=a6a_2 = a_6;
  • (1,3,4,6)(1, 3, 4, 6): a1=a4a_1 = a_4 and a3=a6a_3 = a_6.

在第一个测试用例中,任意四个下标 i<j<k<li \lt j \lt k \lt l 均为合法的,因此答案即为满足条件的四元组个数。

在第二个测试用例中,共有 22 个合法的四元组:

  • (1,2,4,6)(1, 2, 4, 6):满足 a1=a4a_1 = a_4 且 a2=a6a_2 = a_6;
  • (1,3,4,6)(1, 3, 4, 6):满足 a1=a4a_1 = a_4 且 a3=a6a_3 = a_6。

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

首页