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=0.
Note that zero-based indexing is used in this problem.
For an array b consisting of m positive integers, define f(b) as follows.
For a non-negative integer k, we say that b can be k-sorted if it can be sorted in non-decreasing order by performing the following operation any number of times:
- Choose two indices i and j (0≤i<j≤m−1) such that i⊕j≤k∗. Note that the condition applies to the indices i and j, not to the elements bi and bj.
- Swap the elements bi and bj.
The value f(b) is defined as the smallest non-negative integer k such that the array b can be k-sorted.
You are given an array a of length n, consisting of positive integers. You will perform q updates on a. Each update has the following form:
- ix: assign ai=x.
Note that the updates are persistent. In other words, each update affects all subsequent states of the array.
For each of the q+1 states of a — the initial state and the state after each of the q updates — find the value of f(a).
∗⊕ denotes the bitwise XOR operation
这是该问题的简单版本。两个版本的唯一区别在于本版本中 q=0。
注意:本题中采用从 0 开始的索引。
对于一个由 m 个正整数组成的数组 b,定义函数 f(b) 如下:
对于一个非负整数 k,若可通过执行以下操作任意多次将 b 排序为非递减顺序,则称 b 可被 k-排序:
- 选择两个下标 i 和 j(满足 0≤i<j≤m−1),使得 i⊕j≤k∗。注意该条件约束的是下标 i 和 j,而非元素 bi 和 bj。
- 交换元素 bi 和 bj。
函数 f(b) 定义为使得数组 b 可被 k-排序的最小非负整数 k。
你被给定一个长度为 n 的正整数数组 a。你将对 a 执行 q 次更新操作。每次更新的形式如下:
- ix:令 ai=x。
注意:这些更新是持久化的。换言之,每次更新都会影响数组后续的所有状态。
对于 a 的 q+1 个状态(即初始状态,以及每次更新后的状态),请分别求出 f(a) 的值。
∗⊕ 表示 按位异或运算
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and q (1≤n≤106,q=0) — the length of the array a and the number of updates.
The second line of each test case contains n integers a0,a1,…,an−1 (1≤ai≤109) — the array a.
The j-th of the following q lines contains two integers ij and xj (0≤ij<n, 1≤xj≤109) — the description of the j-th update. This update means that the assignment aij=xj is performed.
It is guaranteed that the sum of n over all test cases does not exceed 106.
It is guaranteed that the sum of q over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(1≤n≤106,q=0)——分别表示数组 a 的长度和更新操作的次数。
每个测试用例的第二行包含 n 个整数 a0,a1,…,an−1(1≤ai≤109)——即数组 a。
接下来的 q 行中,第 j 行包含两个整数 ij 和 xj(0≤ij<n,1≤xj≤109)——表示第 j 次更新操作。该更新操作将执行赋值 aij=xj。
保证所有测试用例的 n 之和不超过 106。
保证所有测试用例的 q 之和不超过 106。
输出格式
For each test case, output q+1 integers — the values of f(a) for the initial state of the array and after each of the q updates, in order.
对于每个测试用例,输出 q+1 个整数——即数组初始状态下的 f(a) 值,以及每次 q 次更新后的 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]. It is already sorted, so f(a)=0.
In the second example, the array is a=[109,109−1]. We can swap a0 and a1, transforming a as follows: [109,109−1]→[109−1,109]. Therefore, f(a)=0⊕1=1.
In the third example, the array is a=[2,5,3,4,1,6]. We can perform swaps using the index pairs (0,1) and (0,4), transforming a as follows: [2,5,3,4,1,6]→[5,2,3,4,1,6], [5,2,3,4,1,6]→[1,2,3,4,5,6]. It can be shown that no smaller value of k is sufficient, so f(a)=max(0⊕1,0⊕4)=4.
在第一个例子中,数组为 a=[2,3,4]。该数组已有序,因此 f(a)=0。
在第二个例子中,数组为 a=[109,109−1]。我们可以交换 a0 和 a1,将 a 变换如下:[109,109−1]→[109−1,109]。因此,f(a)=0⊕1=1。
在第三个例子中,数组为 a=[2,5,3,4,1,6]。我们可以使用索引对 (0,1) 和 (0,4) 进行交换,将 a 变换如下:[2,5,3,4,1,6]→[5,2,3,4,1,6],[5,2,3,4,1,6]→[1,2,3,4,5,6]。可以证明不存在更小的 k 满足要求,因此 f(a)=max(0⊕1,0⊕4)=4。
输入解题思路,AI测评打分。不知道怎么写?