CF1930F.Maximize the Difference
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For an array b of m non-negative integers, define f(b) as the maximum value of i=1maxm(bi∣x)−i=1minm(bi∣x) over all possible non-negative integers x, where ∣ is bitwise OR operation.
You are given integers n and q. You start with an empty array a. Process the following q queries:
- v: append v to the back of a and then output f(a). It is guaranteed that 0≤v<n.
The queries are given in a modified way.
对于一个包含 m 个非负整数的数组 b,定义 f(b) 为:对所有可能的非负整数 x,表达式 i=1maxm(bi∣x)−i=1minm(bi∣x) 的最大值,其中 ∣ 表示按位或运算。
给定整数 n 和 q。你从一个空数组 a 开始,依次处理以下 q 个查询:
- v:将 v 追加到数组 a 的末尾,然后输出 f(a)。保证 0≤v<n。
这些查询以一种修改后的方式给出。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤2⋅105) — the number of test cases. The description of the test cases follows.
The first line of each test case contains two integers n and q (1≤n≤222, 1≤q≤106) — the number of queries.
The second line of each test case contains q space-separated integers e1,e2,…,eq (0≤ei<n) — the encrypted values of v.
Let lasti equal the output of the (i−1)-th query for i≥2 and lasti=0 for i=1. Then the value of v for the i-th query is (ei+lasti) modulo n.
It is guaranteed that the sum of n over all test cases does not exceed 222 and the sum of q over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤2⋅105),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(1≤n≤222,1≤q≤106)—— 表示查询次数。
每个测试用例的第二行包含 q 个以空格分隔的整数 e1,e2,…,eq(0≤ei<n)—— 即 v 的加密值。
令 lasti 表示第 (i−1) 次查询的输出结果(当 i≥2 时),并规定 lasti=0(当 i=1 时)。则第 i 次查询中 v 的值为 (ei+lasti)modn。
保证所有测试用例的 n 之和不超过 222,且所有测试用例的 q 之和不超过 106。
输出格式
For each test case, print q integers. The i-th integer is the output of the i-th query.
对于每个测试用例,输出 q 个整数。其中第 i 个整数为第 i 个查询的结果。
输入输出样例
输入#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]. For i=1, the answer is always 0, irrespective of x. For i=2, we can select x=5.
In the second test case, the final a=[3,1,0,5].
在第一个测试用例中,最终的数组 a=[1,2]。对于 i=1,答案恒为 0,与 x 的取值无关。对于 i=2,我们可以选择 x=5。
在第二个测试用例中,最终的数组 a=[3,1,0,5]。
输入解题思路,AI测评打分。不知道怎么写?