CF1408H.Rainbow Triples
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a sequence a1,a2,…,an of non-negative integers.
You need to find the largest number m of triples (i1,j1,k1) , (i2,j2,k2) , ..., (im,jm,km) such that:
- 1≤ip<jp<kp≤n for each p in 1,2,…,m ;
- aip=akp=0 , ajp=0 ;
- all aj1,aj2,…,ajm are different;
- all i1,j1,k1,i2,j2,k2,…,im,jm,km are different.
输入格式
The first line of input contains one integer t ( 1≤t≤500000 ): the number of test cases.
The first line of each test case contains one integer n ( 1≤n≤500000 ).
The second line contains n integers a1,a2,…,an ( 0≤ai≤n ).
The total sum of n is at most 500000 .
输出格式
For each test case, print one integer m : the largest number of proper triples that you can find.
输入输出样例
输入#1
8 1 1 2 0 0 3 0 1 0 6 0 0 1 2 0 0 6 0 1 0 0 1 0 6 0 1 3 2 0 0 6 0 0 0 0 5 0 12 0 1 0 2 2 2 0 0 3 3 4 0
输出#1
0 0 1 2 1 1 1 2
说明/提示
In the first two test cases, there are not enough elements even for a single triple, so the answer is 0 .
In the third test case we can select one triple (1,2,3) .
In the fourth test case we can select two triples (1,3,5) and (2,4,6) .
In the fifth test case we can select one triple (1,2,3) . We can't select two triples (1,2,3) and (4,5,6) , because a2=a5 .