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(⋅)f(\cdot) for each prefix of aa.

For any array [c1,c2,…,cm][c_1, c_2, \ldots, c_m], we define f(c)f(c) as the maximum possible mex⁡(c)\operatorname{mex}(c)∗^{\text{∗}} that can be achieved by performing the following operation exactly once:

  • Choose an integer array [b1,b2,…,bm][b_1, b_2, \ldots, b_m] such that bi≥1b_i \ge 1 for all 1≤i≤m1 \le i \le m;
  • Set ci:=ci  mod  bic_i := c_i \, \bmod \, b_i†^{\text{†}} for every 1≤i≤m1 \le i \le m.

You are given an array aa consisting of nn non-negative integers. For each prefix a(i)=[a1,a2,…,ai]a^{(i)} = [a_1, a_2, \ldots, a_i], determine the value of f(a(i))f(a^{(i)}).

∗^{\text{∗}}mex⁡(c)\operatorname{mex}(c) denotes the minimum excluded (MEX) of the integers in cc. For example, mex⁡([2,2,1])=0\operatorname{mex}([2,2,1])=0 because 00 does not belong to the array, and mex⁡([0,3,1,2])=4\operatorname{mex}([0,3,1,2])=4 because 00, 11, 22, and 33 appear in the array, but 44 does not.

†^{\text{†}}u mod vu \bmod v denotes the remainder from dividing uu by vv.

这是本题的困难版本。在本版本中,你需要对数组 aa 的每个前缀分别求出 f(⋅)f(\cdot) 的值。

对于任意数组 [c1,c2,…,cm][c_1, c_2, \ldots, c_m],我们定义 f(c)f(c) 为:在恰好执行一次如下操作的前提下,所能达到的最大可能的 mex⁡(c)\operatorname{mex}(c)∗^{\text{∗}} 值:

  • 选择一个整数数组 [b1,b2,…,bm][b_1, b_2, \ldots, b_m],满足对所有 1≤i≤m1 \le i \le m 均有 bi≥1b_i \ge 1;
  • 对每个 1≤i≤m1 \le i \le m,令 ci:=ci  mod  bic_i := c_i \, \bmod \, b_i†^{\text{†}}。

给定一个由 nn 个非负整数组成的数组 aa。对每个前缀 a(i)=[a1,a2,…,ai]a^{(i)} = [a_1, a_2, \ldots, a_i],求出 f(a(i))f(a^{(i)}) 的值。

∗^{\text{∗}}mex⁡(c)\operatorname{mex}(c) 表示数组 cc 中整数的最小未出现值(MEX)。例如,mex⁡([2,2,1])=0\operatorname{mex}([2,2,1])=0,因为 00 不在该数组中;而 mex⁡([0,3,1,2])=4\operatorname{mex}([0,3,1,2])=4,因为 00、11、22 和 33 均出现在该数组中,但 44 没有出现。

†^{\text{†}}u mod vu \bmod v 表示 uu 除以 vv 所得的余数。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each testcase contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the length of the array aa.

The second line of each testcase contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1060 \le a_i \le 10^6) — the elements of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5. It is guaranteed that the sum of max⁡(a1,a2,…,an)\max(a_1,a_2,\ldots,a_n) over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1060 \le a_i \le 10^6)—— 数组 aa 的元素。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。保证所有测试用例的 max⁡(a1,a2,…,an)\max(a_1,a_2,\ldots,a_n) 之和不超过 10610^6。

输出格式

For each testcase, output nn integers — where the ii-th integer represents the value of f([a1,a2,…,ai])f([a_1, a_2, \ldots, a_i]).

对于每个测试用例,输出 nn 个整数——其中第 ii 个整数表示 f([a1,a2,…,ai])f([a_1, a_2, \ldots, a_i]) 的值。

输入输出样例

  • 输入#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]a^{(1)} = [0], choosing b=[1]b = [1] gives mex⁡=1\operatorname{mex} = 1.
  • a(2)=[0,1]a^{(2)} = [0, 1], choosing b=[1,2]b = [1, 2] gives mex⁡=2\operatorname{mex} = 2.
  • a(3)=[0,1,2]a^{(3)} = [0, 1, 2], choosing b=[1,2,3]b = [1, 2, 3] gives mex⁡=3\operatorname{mex} = 3.
  • a(4)=[0,1,2,3]a^{(4)} = [0, 1, 2, 3], choosing b=[1,2,3,4]b = [1, 2, 3, 4] gives mex⁡=4\operatorname{mex} = 4.

Consider the second testcase,

  • a(1)=[6]a^{(1)} = [6], choosing b=[6]b = [6] gives mex⁡=1\operatorname{mex} = 1.
  • a(2)=[6,7]a^{(2)} = [6, 7], choosing b=[3,3]b = [3, 3] gives mex⁡=2\operatorname{mex} = 2.

考虑第一个测试用例:

  • a(1)=[0]a^{(1)} = [0],选择 b=[1]b = [1] 可得 mex⁡=1\operatorname{mex} = 1。
  • a(2)=[0,1]a^{(2)} = [0, 1],选择 b=[1,2]b = [1, 2] 可得 mex⁡=2\operatorname{mex} = 2。
  • a(3)=[0,1,2]a^{(3)} = [0, 1, 2],选择 b=[1,2,3]b = [1, 2, 3] 可得 mex⁡=3\operatorname{mex} = 3。
  • a(4)=[0,1,2,3]a^{(4)} = [0, 1, 2, 3],选择 b=[1,2,3,4]b = [1, 2, 3, 4] 可得 mex⁡=4\operatorname{mex} = 4。

考虑第二个测试用例:

  • a(1)=[6]a^{(1)} = [6],选择 b=[6]b = [6] 可得 mex⁡=1\operatorname{mex} = 1。
  • a(2)=[6,7]a^{(2)} = [6, 7],选择 b=[3,3]b = [3, 3] 可得 mex⁡=2\operatorname{mex} = 2。

输入解题思路,AI测评打分。不知道怎么写?

首页