#P16607. [SYSUCPC 2025] Divisor Transformation

[SYSUCPC 2025] Divisor Transformation

题目描述

Dr.Z\texttt{Dr.Z} is studying a permutation pp of length nn (i.e., pp contains each integer from 11 to nn exactly once). He performs qq experiments, each defined by parameters (l,r,x)(l, r, x).

In each experiment, he processes the subarray pl,pl+1,,prp_l, p_{l+1}, \dots, p_r sequentially. Starting with value xx, for each element pip_i in the subarray:

  • If xpix \mid p_i (xx divides pip_i), then xx becomes pi/xp_i / x
  • Else if pixp_i \mid x (pip_i divides xx), then xx becomes x/pix / p_i
  • Otherwise, xx remains unchanged

Dr.Z\texttt{Dr.Z} needs your help to compute:

  • The final value of xx after processing each experiment
  • The total number of times either xpix \mid p_i or pixp_i \mid x was satisfied during the process

输入格式

The first line contains two integers n,q (1n,q500000)n,q\ (1 \le n, q \le 500000)

The second line contains nn distinct integers $p_1, p_2, \dots, p_n\ (\forall 1\le i\le n,1\le p_i\le n)$

The next qq lines each contain 3 integers l,r,x (1lrn,1xn)l,r,x\ (1 \le l \le r \le n,1 \le x \le n)

输出格式

For each experiment, output two integers:

  • The final value of xx
  • The total count of cases where either xpix \mid p_i or pixp_i \mid x
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