CF2201D.Binary Not Search and Queries

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

For a sequence bb consisting of mm integers, the set S(b)S(b) is defined as the set of tuples (i,j,k)(i,j,k) that satisfy the following conditions:

  • ii, jj, kk are integers;
  • 1≤k<m1 \le k \lt m;
  • 1≤i<j≤m−k+11 \le i \lt j \le m-k+1;
  • For every element vv in bb, vv appears the same number of times in [bi,bi+1,…,bi+k−1][b_i,b_{i+1},\ldots,b_{i+k-1}] and [bj,bj+1,…,bj+k−1][b_j,b_{j+1},\ldots,b_{j+k-1}].

For example, when b=[1,2,1,2]b=[1,2,1,2], the tuple (1,3,2)(1,3,2) is an element of S(b)S(b) because 11 and 22 both appear once in [b1,b2][b_1,b_2] and [b3,b4][b_3,b_4].

Additionally, we define two functions over sequences of positive integers:

  • k_\max(b) is defined as the maximum value of kk over all elements (i,j,k)(i,j,k) of S(b)S(b);
  • f(b)f(b) is defined as the number of different elements (i,j,k)(i,j,k) of S(b)S(b) such that k=k_\max(b).

Exceptionally, when the set S(b)S(b) is empty, they are defined as k_\max(b)=0 and f(b)=0f(b)=0.

You are given a sequence aa of nn integers. Please answer qq queries of the following kind:

  • i  xi\;x: Change the value of aia_i to xx. Then, find the values of k_\max(a) and f(a)f(a).

Do note that the updates are persistent. In other words, the update from one query affects the later queries as well.

对于一个由 mm 个整数组成的序列 bb,集合 S(b)S(b) 定义为满足以下条件的所有三元组 (i,j,k)(i,j,k) 构成的集合:

  • ii、jj、kk 均为整数;
  • 1≤k<m1 \le k \lt m;
  • 1≤i<j≤m−k+11 \le i \lt j \le m-k+1;
  • 对于 bb 中的每个元素 vv,其在子数组 [bi,bi+1,…,bi+k−1][b_i,b_{i+1},\ldots,b_{i+k-1}] 与子数组 [bj,bj+1,…,bj+k−1][b_j,b_{j+1},\ldots,b_{j+k-1}] 中出现的次数相同。

例如,当 b=[1,2,1,2]b=[1,2,1,2] 时,三元组 (1,3,2)(1,3,2) 属于 S(b)S(b),因为 11 和 22 在子数组 [b1,b2][b_1,b_2] 与 [b3,b4][b_3,b_4] 中均各出现一次。

此外,我们定义两个作用于正整数序列上的函数:

  • k_\max(b) 定义为所有属于 S(b)S(b) 的三元组 (i,j,k)(i,j,k) 中 kk 的最大值;
  • f(b)f(b) 定义为 S(b)S(b) 中满足 k=k_\max(b) 的不同三元组 (i,j,k)(i,j,k) 的个数。

特殊地,当集合 S(b)S(b) 为空集时,定义 k_\max(b)=0 且 f(b)=0f(b)=0。

给定一个长度为 nn 的整数序列 aa,请回答 qq 个如下形式的查询:

  • i  xi\;x:将 aia_i 的值修改为 xx;然后,求出 k_\max(a) 和 f(a)f(a) 的值。

请注意,这些更新是持久化的。换言之,前一个查询所执行的更新会影响后续所有查询。

输入格式

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 (2≤n≤200 0002 \le n \le 200\,000, 1≤q≤100 0001 \le q \le 100\,000).

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤n1 \le a_i \le n).

Each of the following qq lines contains two integers iji_j and xjx_j denoting the jj-th query (1≤ij,xj≤n1 \le i_j,x_j \le n).

It is guaranteed that the sum of nn over all test cases does not exceed 200 000200\,000.

It is guaranteed that the sum of qq over all test cases does not exceed 100 000100\,000.

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

每个测试用例的第一行包含两个整数 nn 和 qq(2≤n≤200 0002 \le n \le 200\,000,1≤q≤100 0001 \le q \le 100\,000)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤n1 \le a_i \le n)。

接下来的 qq 行中,每行包含两个整数 iji_j 和 xjx_j,表示第 jj 个查询(1≤ij,xj≤n1 \le i_j,x_j \le n)。

保证所有测试用例的 nn 之和不超过 200 000200\,000。

保证所有测试用例的 qq 之和不超过 100 000100\,000。

输出格式

For each test case, output qq lines.

On the jj-th line, you must output the values of k_\max(a) and f(a)f(a) for the jj-th query.

It can be shown that both values will never exceed 101110^{11} under the constraints of this problem.

对于每个测试用例,输出 qq 行。

在第 jj 行中,你必须输出第 jj 个查询对应的 k_\max(a) 和 f(a)f(a) 的值。

可以证明,在本题的约束条件下,这两个值均不会超过 101110^{11}。

输入输出样例

  • 输入#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]a=[1,2,1,2]. The elements of the set S(a)S(a) are as follows:

  • (1,3,1)(1,3,1): [1,2,1,2][\color{red}{1},2,\color{blue}{1},2];
  • (2,4,1)(2,4,1): [1,2,1,2][1,\color{red}{2},1,\color{blue}{2}];
  • (1,2,2)(1,2,2): [1,2,1,2][\color{red}{1},\color{magenta}{2},\color{blue}{1},2];
  • (1,3,2)(1,3,2): [1,2,1,2][\color{red}{1},\color{red}{2},\color{blue}{1},\color{blue}{2}];
  • (2,3,2)(2,3,2): [1,2,1,2][1,\color{red}{2},\color{magenta}{1},\color{blue}{2}].

Therefore, k_\max(a)=2, and f(a)=3f(a)=3 because there are three elements (i,j,k)(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]a=[1,3,2,4,5]. The set S(a)S(a) is empty at this point.

By definition, you should output k_\max(a)=0 and f(a)=0f(a)=0 because S(a)S(a) is currently empty.

在第二个测试用例的第一个查询操作后,a=[1,2,1,2]a=[1,2,1,2]。集合 S(a)S(a) 的元素如下:

  • (1,3,1)(1,3,1):[1,2,1,2][\color{red}{1},2,\color{blue}{1},2];
  • (2,4,1)(2,4,1):[1,2,1,2][1,\color{red}{2},1,\color{blue}{2}];
  • (1,2,2)(1,2,2):[1,2,1,2][\color{red}{1},\color{magenta}{2},\color{blue}{1},2];
  • (1,3,2)(1,3,2):[1,2,1,2][\color{red}{1},\color{red}{2},\color{blue}{1},\color{blue}{2}];
  • (2,3,2)(2,3,2):[1,2,1,2][1,\color{red}{2},\color{magenta}{1},\color{blue}{2}]。

因此,k_\max(a)=2,且由于存在三个满足 k=k_\max(a)=2 的三元组 (i,j,k)(i,j,k),故 f(a)=3f(a)=3。

在第三个测试用例的第二个查询操作后,a=[1,3,2,4,5]a=[1,3,2,4,5]。此时集合 S(a)S(a) 为空。

根据定义,由于 S(a)S(a) 当前为空,应输出 k_\max(a)=0 和 f(a)=0f(a)=0。

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

首页