CF1930F.Maximize the Difference

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For an array bb of mm non-negative integers, define f(b)f(b) as the maximum value of max⁡i=1m(bi∣x)−min⁡i=1m(bi∣x)\max\limits_{i = 1}^{m} (b_i | x) - \min\limits_{i = 1}^{m} (b_i | x) over all possible non-negative integers xx, where ∣| is bitwise OR operation.

You are given integers nn and qq. You start with an empty array aa. Process the following qq queries:

  • vv: append vv to the back of aa and then output f(a)f(a). It is guaranteed that 0≤v<n0 \leq v \lt n.

The queries are given in a modified way.

对于一个包含 mm 个非负整数的数组 bb,定义 f(b)f(b) 为:对所有可能的非负整数 xx,表达式 max⁡i=1m(bi∣x)−min⁡i=1m(bi∣x)\max\limits_{i = 1}^{m} (b_i | x) - \min\limits_{i = 1}^{m} (b_i | x) 的最大值,其中 ∣| 表示按位或运算。

给定整数 nn 和 qq。你从一个空数组 aa 开始,依次处理以下 qq 个查询:

  • vv:将 vv 追加到数组 aa 的末尾,然后输出 f(a)f(a)。保证 0≤v<n0 \leq v \lt n。

这些查询以一种修改后的方式给出。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤2⋅1051 \leq t \leq 2 \cdot 10^5) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and qq (1≤n≤2221 \leq n \leq 2^{22}, 1≤q≤1061 \leq q \leq 10^6) — the number of queries.

The second line of each test case contains qq space-separated integers e1,e2,…,eqe_1,e_2,\ldots,e_q (0≤ei<n0 \leq e_i \lt n) — the encrypted values of vv.

Let lasti\mathrm{last}_i equal the output of the (i−1)(i-1)-th query for i≥2i\geq 2 and lasti=0\mathrm{last}_i=0 for i=1i=1. Then the value of vv for the ii-th query is (ei+lastie_i + \mathrm{last}_i) modulo nn.

It is guaranteed that the sum of nn over all test cases does not exceed 2222^{22} and the sum of qq over all test cases does not exceed 10610^6.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤2⋅1051 \leq t \leq 2 \cdot 10^5),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n≤2221 \leq n \leq 2^{22},1≤q≤1061 \leq q \leq 10^6)—— 表示查询次数。

每个测试用例的第二行包含 qq 个以空格分隔的整数 e1,e2,…,eqe_1,e_2,\ldots,e_q(0≤ei<n0 \leq e_i \lt n)—— 即 vv 的加密值。

令 lasti\mathrm{last}_i 表示第 (i−1)(i-1) 次查询的输出结果(当 i≥2i \geq 2 时),并规定 lasti=0\mathrm{last}_i = 0(当 i=1i = 1 时)。则第 ii 次查询中 vv 的值为 (ei+lasti) mod n(e_i + \mathrm{last}_i) \bmod n。

保证所有测试用例的 nn 之和不超过 2222^{22},且所有测试用例的 qq 之和不超过 10610^6。

输出格式

For each test case, print qq integers. The ii-th integer is the output of the ii-th query.

对于每个测试用例,输出 qq 个整数。其中第 ii 个整数为第 ii 个查询的结果。

输入输出样例

  • 输入#1

    2
    5 2
    1 2
    7 4
    3 1 5 2

    输出#1

    0 2
    0 2 3 5

说明/提示

In the first test case, the final a=[1,2]a=[1,2]. For i=1i=1, the answer is always 00, irrespective of xx. For i=2i=2, we can select x=5x=5.

In the second test case, the final a=[3,1,0,5]a=[3,1,0,5].

在第一个测试用例中,最终的数组 a=[1,2]a=[1,2]。对于 i=1i=1,答案恒为 00,与 xx 的取值无关。对于 i=2i=2,我们可以选择 x=5x=5。

在第二个测试用例中,最终的数组 a=[3,1,0,5]a=[3,1,0,5]。

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

首页