CF1408H.Rainbow Triples
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:256MB
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.
给你一个长度为 n 的非负整数序列 a1,a2,…,an。
你需要找出满足以下条件的三元组 (i1,j1,k1), (i2,j2,k2), ..., (im,jm,km) 的最大可能个数 m:
- 对每个 p=1,2,…,m,均有 1≤ip<jp<kp≤n;
- aip=akp=0,且 ajp=0;
- 所有 aj1,aj2,…,ajm 互不相同;
- 所有下标 i1,j1,k1,i2,j2,k2,…,im,jm,km 互不相同。
输入格式
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.
输入的第一行包含一个整数 t(1≤t≤500000):测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤500000)。
第二行包含 n 个整数 a1,a2,…,an(0≤ai≤n)。
所有测试用例中 n 的总和不超过 500000。
输出格式
For each test case, print one integer m: the largest number of proper triples that you can find.
对于每个测试用例,输出一个整数 m:你能找到的合法三元组的最大数量。
输入输出样例
输入#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.
在前两个测试用例中,元素数量甚至不足以构成一个三元组,因此答案为 0。
在第三个测试用例中,我们可以选择一个三元组 (1,2,3)。
在第四个测试用例中,我们可以选择两个三元组 (1,3,5) 和 (2,4,6)。
在第五个测试用例中,我们可以选择一个三元组 (1,2,3)。我们不能选择两个三元组 (1,2,3) 和 (4,5,6),因为 a2=a5。
输入解题思路,AI测评打分。不知道怎么写?