#CF1703F. Yet Another Problem About Pairs Satisfying an Inequality

Yet Another Problem About Pairs Satisfying an Inequality

Yet Another Problem About Pairs Satisfying an Inequality

  • 时间限制:2 秒
  • 内存限制:256 MiB

题目描述

给定一个长度为 nn 的整数数组 a1,a2,…,ana_1,a_2,\ldots,a_n,下标从 11 开始。请统计满足

ai<i<aj<ja_i<i<a_j<j

的下标对 (i,j)(i,j) 的数量。所有不等号均为严格不等号,数组中的数值不必互不相同。

输入格式

第一行包含整数 tt,表示测试用例数。

每个测试用例第一行包含整数 nn,第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n。

输出格式

对每个测试用例输出一行,包含一个整数,表示符合条件的下标对数量。答案不取模。

样例输入 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

数据范围

对于所有测试数据,保证:

  • 1≤t≤10001\le t\le 1000,2≤n≤2×1052\le n\le 2\times 10^5,0≤ai≤1090\le a_i\le 10^9。同一输入文件中所有测试用例的 nn 之和不超过 2×1052\times 10^5。
测试点编号 分值 特殊限制
1∼41\sim4 55 n≤2000n\le 2000 且 ∑n≤6000\sum n\le 6000
5∼85\sim8 aa 中正数至多有一种不同取值
9∼139\sim13 a1≤a2≤⋯≤ana_1\le a_2\le\cdots\le a_n
14∼2014\sim20 无