CF1703F.Yet Another Problem About Pairs Satisfying an Inequality

普及/提高-

通过率:0%

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 1i,jn1 \leq i, j \leq n such that ai<i<aj<ja_i < i < a_j < j .

输入格式

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

The first line of each test case contains an integer nn ( 2n21052 \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 ( 0ai1090 \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 21052 \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++).

输入输出样例

  • 输入#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 < 2 < 3 < 4 .
  • The pair (2,8)(2, 8) is true because a2=1a_2 = 1 , a8=4a_8 = 4 and 1<2<4<81 < 2 < 4 < 8 .
  • The pair (3,8)(3, 8) is true because a3=2a_3 = 2 , a8=4a_8 = 4 and 2<3<4<82 < 3 < 4 < 8 .
首页