#P15080. [ICPC 2024 Chengdu R] Good Partitions

    ID: 16926 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>数学线段树2024最大公约数 gcdICPC

[ICPC 2024 Chengdu R] Good Partitions

题目描述

Lawliet has a sequence of numbers of length nn, denoted as a1,a2,,ana_1, a_2, \ldots, a_n, and he wants to determine how many good partitions exist.

A partition size kk is considered a good partition size if it satisfies 1kn1 \leq k \leq n and, after dividing the sequence aa into parts by partition size, each resulting sub-sequence is non-decreasing. The partitioning method is as follows:

  • The sequence aa is divided into nk\lceil \frac{n}{k} \rceil parts.
  • For the ii-th part (1ink11 \leq i \leq \lceil \frac{n}{k} \rceil - 1), the elements are $a_{(i - 1) \times k + 1}, a_{(i - 1) \times k + 2}, \ldots, a_{i \times k}$.
  • For the nk\lceil \frac{n}{k} \rceil-th part, the elements are $a_{(\lceil \frac{n}{k} \rceil - 1) \times k + 1}, \ldots, a_n$. Note that the length of the last part may be less than kk.

Lawliet finds this problem too simple, so he will make qq modifications. Each modification provides two positive integers pp and vv, indicating that the value of apa_p will be changed to vv.

Your task is to help Lawliet calculate the number of good partition sizes before any modifications and after each modification.

输入格式

The first line contains an integer TT (1T101\le T \le 10), representing the number of test cases.

For each test case, the first line contains two integers nn (1n21051 \le n \le 2 \cdot 10^5) and qq (1q21051 \le q \le 2 \cdot 10^5), representing the length of the sequence and the number of modifications.

The second line contains nn integers, representing the sequence a1,a2,,ana_1, a_2, \ldots, a_n (1ai21091\le a_i\le 2\cdot 10^9).

The following qq lines each contain two integers pp (1pn1 \le p \le n) and vv (1v21091 \le v \le 2 \cdot 10^9), indicating that the element at the pp-th position in the sequence will be modified to vv.

It is guaranteed that the sum of nn and the sum of qq over all test cases do not exceed 21052\cdot 10^5, respectively.

输出格式

For each test case, output q+1q + 1 lines, representing the number of good partition sizes before any modifications and after each modification.

1
5 2
4 3 2 6 1
2 5
3 5
1
2
3

提示

Initially, the only good partition size is k=1k = 1.

After the first modification, the sequence becomes [4,5,2,6,1][4, 5, 2, 6, 1]. Both k=1k = 1 and k=2k = 2 are good partition sizes.

After the second modification, the sequence becomes [4,5,5,6,1][4, 5, 5, 6, 1]. The good partition sizes are k=1k = 1, k=2k = 2, and k=4k = 4.