CF2146E.Yet Another MEX Problem
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
We define the weight of an array b consisting of m non-negative integers as the number of indices i (1≤i≤m) satisfying bi>mex(b). Here, mex(b) denotes the minimum excluded (MEX)∗ of the integers in b.
You are given an array a consisting of n non-negative integers. For its subarray† [al,al+1,…,ar], we denote the weight of the subarray as w(l,r).
For every 1≤i≤n, you have to find the maximum weight over all subarrays of a ending at index i. In other words, you have to find 1≤l≤imaxw(l,i) for every 1≤i≤n.
∗The minimum excluded (MEX) of a collection of integers b1,b2,…,bm is defined as the smallest non-negative integer x which does not occur in the collection b.
†An array c is a subarray of an array a if c can be obtained from a by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
我们定义一个由 m 个非负整数组成的数组 b 的权重为满足 bi>mex(b) 的下标 i(其中 1≤i≤m)的个数。这里,mex(b) 表示数组 b 中元素的最小未出现值(MEX)∗。
给定一个由 n 个非负整数组成的数组 a。对于其子数组† [al,al+1,…,ar],我们记该子数组的权重为 w(l,r)。
对每个 1≤i≤n,你需要找出所有以索引 i 结尾的 a 的子数组中权重的最大值。换言之,对每个 1≤i≤n,你需要计算 1≤l≤imaxw(l,i)。
∗ 一组整数 b1,b2,…,bm 的**最小未出现值(MEX)**定义为不在该集合 b 中出现的最小非负整数 x。
† 若数组 c 可通过从数组 a 的开头删除若干(可能为零个或全部)元素、并从结尾删除若干(可能为零个或全部)元素而得到,则称 c 是 a 的一个子数组。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤3⋅105) — the length of a.
The second line contains n integers a1,a2,…,an (0≤ai≤n) — the elements of a.
It is guaranteed that the sum of n over all test cases does not exceed 3⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤3⋅105)—— 数组 a 的长度。
第二行包含 n 个整数 a1,a2,…,an(0≤ai≤n)—— 数组 a 的元素。
保证所有测试用例的 n 值之和不超过 3⋅105。
输出格式
For each test case, output n integers, the i-th integer denoting the maximum weight over all subarrays of a ending at index i, i.e., 1≤l≤imaxw(l,i).
对于每个测试用例,输出 n 个整数,其中第 i 个整数表示所有以索引 i 结尾的子数组 a 的最大权重,即 1≤l≤imaxw(l,i)。
输入输出样例
输入#1
6 1 0 5 2 0 3 0 1 6 0 1 2 3 5 4 7 0 2 2 0 4 1 3 8 2 1 0 3 0 2 1 3 15 0 1 9 1 0 2 5 3 7 0 4 15 2 0 1
输出#1
0 1 1 2 2 1 0 1 2 3 4 5 0 1 2 2 3 2 3 1 2 0 1 1 2 2 3 0 1 2 3 1 1 2 3 4 4 5 6 7 7 3
说明/提示
In the first test case, we have w(1,1)=0, because mex([a1])=1, and there are no indices satisfying ai>1.
In the second test case, we can calculate the weight of each subarray [l,r] by the definition:
- w(1,1)=1. Thus, 1≤l≤1maxw(l,1)=1;
- w(1,2)=1 and w(2,2)=0. Thus, 1≤l≤2maxw(l,2)=1;
- w(1,3)=2 and w(2,3)=w(3,3)=1. Thus, 1≤l≤3maxw(l,3)=2;
- w(1,4)=2, w(2,4)=w(3,4)=1, and w(4,4)=0. Thus, 1≤l≤4maxw(l,4)=2;
- w(1,5)=0, w(2,5)=w(3,5)=1, and w(4,5)=0,w(5,5)=1. Thus, 1≤l≤5maxw(l,5)=1.
For example, w(1,4)=2 because mex([a1,a2,a3,a4])=1, and there are two indices satisfying ai>1 in the subarray: 1 and 3.
在第一个测试用例中,我们有 w(1,1)=0,因为 mex([a1])=1,且不存在满足 ai>1 的下标。
在第二个测试用例中,我们可以根据定义计算每个子数组 [l,r] 的权重:
- w(1,1)=1。因此,1≤l≤1maxw(l,1)=1;
- w(1,2)=1 且 w(2,2)=0。因此,1≤l≤2maxw(l,2)=1;
- w(1,3)=2 且 w(2,3)=w(3,3)=1。因此,1≤l≤3maxw(l,3)=2;
- w(1,4)=2,w(2,4)=w(3,4)=1,且 w(4,4)=0。因此,1≤l≤4maxw(l,4)=2;
- w(1,5)=0,w(2,5)=w(3,5)=1,且 w(4,5)=0、w(5,5)=1。因此,1≤l≤5maxw(l,5)=1。
例如,w(1,4)=2,因为 mex([a1,a2,a3,a4])=1,且该子数组中有两个下标满足 ai>1:1 和 3。
输入解题思路,AI测评打分。不知道怎么写?