CF2226E.Mental Monumental (Hard Version)
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the hard version of this problem. In this version, you are required to find the values of f(⋅) for each prefix of a.
For any array [c1,c2,…,cm], we define f(c) as the maximum possible mex(c)∗ that can be achieved by performing the following operation exactly once:
- Choose an integer array [b1,b2,…,bm] such that bi≥1 for all 1≤i≤m;
- Set ci:=cimodbi† for every 1≤i≤m.
You are given an array a consisting of n non-negative integers. For each prefix a(i)=[a1,a2,…,ai], determine the value of f(a(i)).
∗mex(c) denotes the minimum excluded (MEX) of the integers in c. For example, mex([2,2,1])=0 because 0 does not belong to the array, and mex([0,3,1,2])=4 because 0, 1, 2, and 3 appear in the array, but 4 does not.
†umodv denotes the remainder from dividing u by v.
这是本题的困难版本。在本版本中,你需要对数组 a 的每个前缀分别求出 f(⋅) 的值。
对于任意数组 [c1,c2,…,cm],我们定义 f(c) 为:在恰好执行一次如下操作的前提下,所能达到的最大可能的 mex(c)∗ 值:
- 选择一个整数数组 [b1,b2,…,bm],满足对所有 1≤i≤m 均有 bi≥1;
- 对每个 1≤i≤m,令 ci:=cimodbi†。
给定一个由 n 个非负整数组成的数组 a。对每个前缀 a(i)=[a1,a2,…,ai],求出 f(a(i)) 的值。
∗mex(c) 表示数组 c 中整数的最小未出现值(MEX)。例如,mex([2,2,1])=0,因为 0 不在该数组中;而 mex([0,3,1,2])=4,因为 0、1、2 和 3 均出现在该数组中,但 4 没有出现。
†umodv 表示 u 除以 v 所得的余数。
输入格式
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 testcase contains a single integer n (1≤n≤2⋅105) — the length of the array a.
The second line of each testcase contains n integers a1,a2,…,an (0≤ai≤106) — the elements of the array a.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105. It is guaranteed that the sum of max(a1,a2,…,an) over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 数组 a 的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai≤106)—— 数组 a 的元素。
保证所有测试用例的 n 之和不超过 2⋅105。保证所有测试用例的 max(a1,a2,…,an) 之和不超过 106。
输出格式
For each testcase, output n integers — where the i-th integer represents the value of f([a1,a2,…,ai]).
对于每个测试用例,输出 n 个整数——其中第 i 个整数表示 f([a1,a2,…,ai]) 的值。
输入输出样例
输入#1
4 4 0 1 2 3 2 6 7 6 8 1 7 6 4 3 9 9 9 8 2 4 4 3 5 3
输出#1
1 2 3 4 1 2 1 2 3 4 5 5 1 2 3 4 5 5 5 6 6
说明/提示
Consider the first testcase,
- a(1)=[0], choosing b=[1] gives mex=1.
- a(2)=[0,1], choosing b=[1,2] gives mex=2.
- a(3)=[0,1,2], choosing b=[1,2,3] gives mex=3.
- a(4)=[0,1,2,3], choosing b=[1,2,3,4] gives mex=4.
Consider the second testcase,
- a(1)=[6], choosing b=[6] gives mex=1.
- a(2)=[6,7], choosing b=[3,3] gives mex=2.
考虑第一个测试用例:
- a(1)=[0],选择 b=[1] 可得 mex=1。
- a(2)=[0,1],选择 b=[1,2] 可得 mex=2。
- a(3)=[0,1,2],选择 b=[1,2,3] 可得 mex=3。
- a(4)=[0,1,2,3],选择 b=[1,2,3,4] 可得 mex=4。
考虑第二个测试用例:
- a(1)=[6],选择 b=[6] 可得 mex=1。
- a(2)=[6,7],选择 b=[3,3] 可得 mex=2。
输入解题思路,AI测评打分。不知道怎么写?