CF2201D.Binary Not Search and Queries
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For a sequence b consisting of m integers, the set S(b) is defined as the set of tuples (i,j,k) that satisfy the following conditions:
- i, j, k are integers;
- 1≤k<m;
- 1≤i<j≤m−k+1;
- For every element v in b, v appears the same number of times in [bi,bi+1,…,bi+k−1] and [bj,bj+1,…,bj+k−1].
For example, when b=[1,2,1,2], the tuple (1,3,2) is an element of S(b) because 1 and 2 both appear once in [b1,b2] and [b3,b4].
Additionally, we define two functions over sequences of positive integers:
- k_\max(b) is defined as the maximum value of k over all elements (i,j,k) of S(b);
- f(b) is defined as the number of different elements (i,j,k) of S(b) such that k=k_\max(b).
Exceptionally, when the set S(b) is empty, they are defined as k_\max(b)=0 and f(b)=0.
You are given a sequence a of n integers. Please answer q queries of the following kind:
- ix: Change the value of ai to x. Then, find the values of k_\max(a) and f(a).
Do note that the updates are persistent. In other words, the update from one query affects the later queries as well.
对于一个由 m 个整数组成的序列 b,集合 S(b) 定义为满足以下条件的所有三元组 (i,j,k) 构成的集合:
- i、j、k 均为整数;
- 1≤k<m;
- 1≤i<j≤m−k+1;
- 对于 b 中的每个元素 v,其在子数组 [bi,bi+1,…,bi+k−1] 与子数组 [bj,bj+1,…,bj+k−1] 中出现的次数相同。
例如,当 b=[1,2,1,2] 时,三元组 (1,3,2) 属于 S(b),因为 1 和 2 在子数组 [b1,b2] 与 [b3,b4] 中均各出现一次。
此外,我们定义两个作用于正整数序列上的函数:
- k_\max(b) 定义为所有属于 S(b) 的三元组 (i,j,k) 中 k 的最大值;
- f(b) 定义为 S(b) 中满足 k=k_\max(b) 的不同三元组 (i,j,k) 的个数。
特殊地,当集合 S(b) 为空集时,定义 k_\max(b)=0 且 f(b)=0。
给定一个长度为 n 的整数序列 a,请回答 q 个如下形式的查询:
- ix:将 ai 的值修改为 x;然后,求出 k_\max(a) 和 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 (2≤n≤200000, 1≤q≤100000).
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n).
Each of the following q lines contains two integers ij and xj denoting the j-th query (1≤ij,xj≤n).
It is guaranteed that the sum of n over all test cases does not exceed 200000.
It is guaranteed that the sum of q over all test cases does not exceed 100000.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(2≤n≤200000,1≤q≤100000)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)。
接下来的 q 行中,每行包含两个整数 ij 和 xj,表示第 j 个查询(1≤ij,xj≤n)。
保证所有测试用例的 n 之和不超过 200000。
保证所有测试用例的 q 之和不超过 100000。
输出格式
For each test case, output q lines.
On the j-th line, you must output the values of k_\max(a) and f(a) for the j-th query.
It can be shown that both values will never exceed 1011 under the constraints of this problem.
对于每个测试用例,输出 q 行。
在第 j 行中,你必须输出第 j 个查询对应的 k_\max(a) 和 f(a) 的值。
可以证明,在本题的约束条件下,这两个值均不会超过 1011。
输入输出样例
输入#1
4 5 3 1 2 3 4 5 3 2 4 1 5 2 4 3 1 2 1 1 4 2 3 2 2 1 5 2 1 3 2 4 5 5 3 5 5 8 3 1 2 3 4 1 2 5 4 7 3 7 4 2 1
输出#1
1 1 3 1 3 3 2 3 2 1 1 2 3 1 0 0 4 10 4 4 4 2
说明/提示
Immediately after the first query of the second test case, a=[1,2,1,2]. The elements of the set S(a) are as follows:
- (1,3,1): [1,2,1,2];
- (2,4,1): [1,2,1,2];
- (1,2,2): [1,2,1,2];
- (1,3,2): [1,2,1,2];
- (2,3,2): [1,2,1,2].
Therefore, k_\max(a)=2, and f(a)=3 because there are three elements (i,j,k) where k=k_\max(a)=2.
Immediately after the second query of the third test case, a=[1,3,2,4,5]. The set S(a) is empty at this point.
By definition, you should output k_\max(a)=0 and f(a)=0 because S(a) is currently empty.
在第二个测试用例的第一个查询操作后,a=[1,2,1,2]。集合 S(a) 的元素如下:
- (1,3,1):[1,2,1,2];
- (2,4,1):[1,2,1,2];
- (1,2,2):[1,2,1,2];
- (1,3,2):[1,2,1,2];
- (2,3,2):[1,2,1,2]。
因此,k_\max(a)=2,且由于存在三个满足 k=k_\max(a)=2 的三元组 (i,j,k),故 f(a)=3。
在第三个测试用例的第二个查询操作后,a=[1,3,2,4,5]。此时集合 S(a) 为空。
根据定义,由于 S(a) 当前为空,应输出 k_\max(a)=0 和 f(a)=0。
输入解题思路,AI测评打分。不知道怎么写?