#P16607. [SYSUCPC 2025] Divisor Transformation
[SYSUCPC 2025] Divisor Transformation
题目描述
is studying a permutation of length (i.e., contains each integer from to exactly once). He performs experiments, each defined by parameters .
In each experiment, he processes the subarray sequentially. Starting with value , for each element in the subarray:
- If ( divides ), then becomes
- Else if ( divides ), then becomes
- Otherwise, remains unchanged
needs your help to compute:
- The final value of after processing each experiment
- The total number of times either or was satisfied during the process
输入格式
The first line contains two integers
The second line contains distinct integers $p_1, p_2, \dots, p_n\ (\forall 1\le i\le n,1\le p_i\le n)$
The next lines each contain 3 integers
输出格式
For each experiment, output two integers:
- The final value of
- The total count of cases where either or
6 6
1 4 3 2 5 6
1 6 4
3 4 2
3 4 4
5 5 1
2 5 3
6 6 4
2 4
1 1
2 1
5 1
2 2
4 0