CF2247D1.XOR Sorting (Easy Version)

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is the easy version of the problem. The only difference between the versions is that in this version, q=0q = 0.

Note that zero-based indexing is used in this problem.

For an array bb consisting of mm positive integers, define f(b)f(b) as follows.

For a non-negative integer kk, we say that bb can be kk-sorted if it can be sorted in non-decreasing order by performing the following operation any number of times:

  1. Choose two indices ii and jj (0≤i<j≤m−10 \le i \lt j \le m - 1) such that i⊕j≤ki \oplus j \le k∗^{\text{∗}}. Note that the condition applies to the indices ii and jj, not to the elements bib_i and bjb_j.
  2. Swap the elements bib_i and bjb_j.

The value f(b)f(b) is defined as the smallest non-negative integer kk such that the array bb can be kk-sorted.

You are given an array aa of length nn, consisting of positive integers. You will perform qq updates on aa. Each update has the following form:

  • i  xi \; x: assign ai=xa_i = x.

Note that the updates are persistent. In other words, each update affects all subsequent states of the array.

For each of the q+1q + 1 states of aa — the initial state and the state after each of the qq updates — find the value of f(a)f(a).

∗^{\text{∗}}⊕\oplus denotes the bitwise XOR operation

这是该问题的简单版本。两个版本的唯一区别在于本版本中 q=0q = 0。

注意:本题中采用从 0 开始的索引。

对于一个由 mm 个正整数组成的数组 bb,定义函数 f(b)f(b) 如下:

对于一个非负整数 kk,若可通过执行以下操作任意多次将 bb 排序为非递减顺序,则称 bb 可被 kk-排序:

  1. 选择两个下标 ii 和 jj(满足 0≤i<j≤m−10 \le i \lt j \le m - 1),使得 i⊕j≤ki \oplus j \le k∗^{\text{∗}}。注意该条件约束的是下标 ii 和 jj,而非元素 bib_i 和 bjb_j。
  2. 交换元素 bib_i 和 bjb_j。

函数 f(b)f(b) 定义为使得数组 bb 可被 kk-排序的最小非负整数 kk。

你被给定一个长度为 nn 的正整数数组 aa。你将对 aa 执行 qq 次更新操作。每次更新的形式如下:

  • i  xi \; x:令 ai=xa_i = x。

注意:这些更新是持久化的。换言之,每次更新都会影响数组后续的所有状态。

对于 aa 的 q+1q + 1 个状态(即初始状态,以及每次更新后的状态),请分别求出 f(a)f(a) 的值。

∗^{\text{∗}}⊕\oplus 表示 按位异或运算

输入格式

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 test case contains two integers nn and qq (1≤n≤106,q=01 \le n \le 10^6, q = 0) — the length of the array aa and the number of updates.

The second line of each test case contains nn integers a0,a1,…,an−1a_0, a_1, \ldots, a_{n - 1} (1≤ai≤1091 \le a_i \le 10^9) — the array aa.

The jj-th of the following qq lines contains two integers iji_j and xjx_j (0≤ij<n0 \le i_j \lt n, 1≤xj≤1091 \le x_j \le 10^9) — the description of the jj-th update. This update means that the assignment aij=xja_{i_j} = x_j is performed.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6.

It is guaranteed that the sum of qq over all test cases does not exceed 10610^6.

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

每个测试用例的第一行包含两个整数 nn 和 qq(1≤n≤106,  q=01 \le n \le 10^6,\; q = 0)——分别表示数组 aa 的长度和更新操作的次数。

每个测试用例的第二行包含 nn 个整数 a0,a1,…,an−1a_0, a_1, \ldots, a_{n - 1}(1≤ai≤1091 \le a_i \le 10^9)——即数组 aa。

接下来的 qq 行中,第 jj 行包含两个整数 iji_j 和 xjx_j(0≤ij<n0 \le i_j \lt n,1≤xj≤1091 \le x_j \le 10^9)——表示第 jj 次更新操作。该更新操作将执行赋值 aij=xja_{i_j} = x_j。

保证所有测试用例的 nn 之和不超过 10610^6。

保证所有测试用例的 qq 之和不超过 10610^6。

输出格式

For each test case, output q+1q + 1 integers — the values of f(a)f(a) for the initial state of the array and after each of the qq updates, in order.

对于每个测试用例,输出 q+1q + 1 个整数——即数组初始状态下的 f(a)f(a) 值,以及每次 qq 次更新后的 f(a)f(a) 值(按顺序)。

输入输出样例

  • 输入#1

    3
    3 0
    2 3 4
    2 0
    1000000000 999999999
    6 0
    2 5 3 4 1 6

    输出#1

    0
    1
    4

说明/提示

In the first example, the array is a=[2,3,4]a = [2, 3, 4]. It is already sorted, so f(a)=0f(a) = 0.

In the second example, the array is a=[109,109−1]a = [10^9, 10^9 - 1]. We can swap a0a_0 and a1a_1, transforming aa as follows: [109,109−1]→[109−1,109][\color{red}{10^9}, \color{red}{10^9 - 1}] \rightarrow [\color{red}{10^9 - 1}, \color{red}{10^9}]. Therefore, f(a)=0⊕1=1f(a) = 0 \oplus 1 = 1.

In the third example, the array is a=[2,5,3,4,1,6]a = [2, 5, 3, 4, 1, 6]. We can perform swaps using the index pairs (0,1)(0, 1) and (0,4)(0, 4), transforming aa as follows: [2,5,3,4,1,6]→[5,2,3,4,1,6][\color{red}{2}, \color{red}{5}, 3, 4, 1, 6] \rightarrow [\color{red}{5}, \color{red}{2}, 3, 4, 1, 6], [5,2,3,4,1,6]→[1,2,3,4,5,6][\color{red}{5}, 2, 3, 4, \color{red}{1}, 6] \rightarrow [\color{red}{1}, 2, 3, 4, \color{red}{5}, 6]. It can be shown that no smaller value of kk is sufficient, so f(a)=max⁡(0⊕1,0⊕4)=4f(a) = \max(0 \oplus 1, 0 \oplus 4) = 4.

在第一个例子中,数组为 a=[2,3,4]a = [2, 3, 4]。该数组已有序,因此 f(a)=0f(a) = 0。

在第二个例子中,数组为 a=[109,109−1]a = [10^9, 10^9 - 1]。我们可以交换 a0a_0 和 a1a_1,将 aa 变换如下:[109,109−1]→[109−1,109][\color{red}{10^9}, \color{red}{10^9 - 1}] \rightarrow [\color{red}{10^9 - 1}, \color{red}{10^9}]。因此,f(a)=0⊕1=1f(a) = 0 \oplus 1 = 1。

在第三个例子中,数组为 a=[2,5,3,4,1,6]a = [2, 5, 3, 4, 1, 6]。我们可以使用索引对 (0,1)(0, 1) 和 (0,4)(0, 4) 进行交换,将 aa 变换如下:[2,5,3,4,1,6]→[5,2,3,4,1,6][\color{red}{2}, \color{red}{5}, 3, 4, 1, 6] \rightarrow [\color{red}{5}, \color{red}{2}, 3, 4, 1, 6],[5,2,3,4,1,6]→[1,2,3,4,5,6][\color{red}{5}, 2, 3, 4, \color{red}{1}, 6] \rightarrow [\color{red}{1}, 2, 3, 4, \color{red}{5}, 6]。可以证明不存在更小的 kk 满足要求,因此 f(a)=max⁡(0⊕1,0⊕4)=4f(a) = \max(0 \oplus 1, 0 \oplus 4) = 4。

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

首页