CF1703F.Yet Another Problem About Pairs Satisfying an Inequality

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array a1,a2,…ana_1, a_2, \dots a_n. Count the number of pairs of indices 1≤i,j≤n1 \leq i, j \leq n such that ai<i<aj<ja_i \lt i \lt a_j \lt j.

给你一个数组 a1,a2,…ana_1, a_2, \dots a_n。统计满足 ai<i<aj<ja_i \lt i \lt a_j \lt j 的下标对 (i,j)(i, j)(其中 1≤i,j≤n1 \leq i, j \leq n)的个数。

输入格式

The first line contains an integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases.

The first line of each test case contains an integer nn (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5) — the length of the array.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤1090 \leq a_i \leq 10^9) — the elements of the array.

It is guaranteed that the sum of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5)—— 数组的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤1090 \leq a_i \leq 10^9)—— 数组的元素。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer — the number of pairs of indices satisfying the condition in the statement.

Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

对于每个测试用例,输出一个整数——即满足题目中所述条件的下标对的数量。

请注意,某些测试用例的答案无法用 32 位整数类型表示,因此在编程语言中应至少使用 64 位整数类型(例如 C++ 中的 long long)。

输入输出样例

  • 输入#1

    5
    8
    1 1 2 3 8 2 1 4
    2
    1 2
    10
    0 2 1 6 3 4 1 2 8 3
    2
    1 1000000000
    3
    0 1000000000 2

    输出#1

    3
    0
    10
    0
    1

说明/提示

For the first test cases the pairs are (i,j)(i, j) = (2,4),(2,8),(3,8){(2, 4), (2, 8), (3, 8)}.

  • The pair (2,4)(2, 4) is true because a2=1a_2 = 1, a4=3a_4 = 3 and 1<2<3<41 \lt 2 \lt 3 \lt 4.
  • The pair (2,8)(2, 8) is true because a2=1a_2 = 1, a8=4a_8 = 4 and 1<2<4<81 \lt 2 \lt 4 \lt 8.
  • The pair (3,8)(3, 8) is true because a3=2a_3 = 2, a8=4a_8 = 4 and 2<3<4<82 \lt 3 \lt 4 \lt 8.

前几个测试用例中的数对为 (i,j)(i, j) = (2,4),(2,8),(3,8){(2, 4), (2, 8), (3, 8)}。

  • 数对 (2,4)(2, 4) 成立,因为 a2=1a_2 = 1,a4=3a_4 = 3,且满足 1<2<3<41 \lt 2 \lt 3 \lt 4。
  • 数对 (2,8)(2, 8) 成立,因为 a2=1a_2 = 1,a8=4a_8 = 4,且满足 1<2<4<81 \lt 2 \lt 4 \lt 8。
  • 数对 (3,8)(3, 8) 成立,因为 a3=2a_3 = 2,a8=4a_8 = 4,且满足 2<3<4<82 \lt 3 \lt 4 \lt 8。

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

首页