CF1764C.Doremy's City Construction
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Doremy's new city is under construction! The city can be regarded as a simple undirected graph with n vertices. The i -th vertex has altitude ai . Now Doremy is deciding which pairs of vertices should be connected with edges.
Due to economic reasons, there should be no self-loops or multiple edges in the graph.
Due to safety reasons, there should not be pairwise distinct vertices u , v , and w such that au≤av≤aw and the edges (u,v) and (v,w) exist.
Under these constraints, Doremy would like to know the maximum possible number of edges in the graph. Can you help her?
Note that the constructed graph is allowed to be disconnected.
输入格式
The input consists of multiple test cases. The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n ( 2≤n≤2⋅105 ) — the number of vertices.
The second line of each test case contains n integers a1,a2,…,an ( 1≤ai≤106 ) — the altitudes of each vertex.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, output the maximum possible number of edges in the graph.
输入输出样例
输入#1
4 4 2 2 3 1 6 5 2 3 1 5 2 12 7 2 4 9 1 4 6 3 7 4 2 3 4 1000000 1000000 1000000 1000000
输出#1
3 9 35 2
说明/提示
In the first test case, there can only be at most 3 edges in the graph. A possible construction is to connect (1,3) , (2,3) , (3,4) . In the picture below the red number above node i is ai .
The following list shows all such u , v , w that the edges (u,v) and (v,w) exist.
- u=1 , v=3 , w=2 ;
- u=1 , v=3 , w=4 ;
- u=2 , v=3 , w=1 ;
- u=2 , v=3 , w=4 ;
- u=4 , v=3 , w=1 ;
- u=4 , v=3 , w=2 .
Another possible construction is to connect (1,4) , (2,4) , (3,4) .
An unacceptable construction is to connect (1,3) , (2,3) , (2,4) , (3,4) . Because when u=4 , v=2 , w=3 , au≤av≤aw holds, and the respective edges exist.