Problem Statement
Lawliet has a sequence of numbers of length \( n \), denoted as \( a_1, a_2, \dots, a_n \), and he wants to determine how many good partitions exist. A partition size \( k \) is considered a good partition size if it satisfies \( 1 \leq k \leq n \) and, after dividing the sequence \( a \) into parts by partition size, each resulting sub-sequence is non-decreasing. The partitioning method is as follows:
-
The sequence \( a \) is divided into \( \lceil \frac{n}{k} \rceil \) parts.
-
For the \( i \)-th part (\( 1 \leq i \leq \lceil \frac{n}{k} \rceil - 1 \)), the elements are \( a_{(i-1) \times k + 1}, a_{(i-1) \times k + 2}, \dots, a_{i \times k} \). _
-
For the \( \lceil \frac{n}{k} \rceil \)-th part, the elements are \( a_{(\lceil \frac{n}{k} \rceil - 1) \times k + 1}, \dots, a_n \). Note that the length of the last part may be less than \( k \).
Lawliet finds this problem too simple, so he will make \( q \) modifications. Each modification provides two positive integers \( p \) and \( v \), indicating that the value of \( a_p \) will be changed to \( v \).
Your task is to help Lawliet calculate the number of good partition sizes before any modifications and after each modification.
Input
The first line contains an integer \( T \) (\( 1 \leq T \leq 10 \)), representing the number of test cases. For each test case:
- The first line contains two integers \( n \) (\( 1 \leq n \leq 2 \cdot 10^5 \)) and \( q \) (\( 1 \leq q \leq 2 \cdot 10^5 \)), representing the length of the sequence and the number of modifications.
- The second line contains \( n \) integers, representing the sequence \( a_1, a_2, \dots, a_n \) (\( 1 \leq a_i \leq 2 \cdot 10^9 \)).
- The following \( q \) lines each contain two integers \( p \) (\( 1 \leq p \leq n \)) and \( v \) (\( 1 \leq v \leq 2 \cdot 10^9 \)), indicating that the element at the \( p \)-th position in the sequence will be modified to \( v \).
- It is guaranteed that the sum of \( n \) and the sum of \( q \) over all test cases do not exceed \( 2 \cdot 10^5 \), respectively.
Output
For each test case, output \( q + 1 \) lines, representing the number of good partition sizes before any modifications and after each modification.
Solving
分析题目易得出:一个序列的好分隔,必定会使得当arr[i] > arr[i+1]时,arr[i] 与 arr[i+!]不在同一个分割之中,记 idx 为 arr[i] 的下标,则对于这一个点,其可能的有效分割是下标 idx 的所有因数。
故对于所有点及对整个序列的所有有效分割,即为所有这种点的下标的最大公因数的因子数,对于单点修改并求取整个序列GCD的信息维护,我们可以选择使用线段树,其每次调用维护的时间为O(logN),可以在规定时限内解决问题。
|
|