CF1930F.Maximize the Difference

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

For an array bb of mm non-negative integers, define f(b)f(b) as the maximum value of maxi=1m(bix)mini=1m(bix)\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 0v<n0 \leq v < n .

The queries are given in a modified way.

输入格式

Each test contains multiple test cases. The first line contains a single integer tt ( 1t21051 \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 ( 1n2221 \leq n \leq 2^{22} , 1q1061 \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 ( 0ei<n0 \leq e_i < n ) — the encrypted values of vv .

Let lasti\mathrm{last}_i equal the output of the (i1)(i-1) -th query for i2i\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 .

输出格式

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

输入输出样例

  • 输入#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] .

首页