#P4256. 公主の#19准备月考

    ID: 2941 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学线段树O2优化素数判断,质数,筛法进制

公主の#19准备月考

Description

The princess is very weak in liberal arts comprehensive, ranking 1100+1100+ in the whole school (and the whole school has just over 11001100 students). After thinking for a long time, she found that if she puts all her time into multiple-choice questions, she can score a bit better.

There are nn questions in liberal arts, numbered from 11 to nn.

The princess computed an estimated value AiA_i for each question. She believes that the answer for a contiguous block of questions will lie between the gcd\gcd and lcm\operatorname{lcm} of their estimated values. Sometimes her thoughts change, and some questions’ estimated values will change. Sometimes multiple-answer questions appear; the number of correct answers for such questions equals the number of common divisors of the estimated values over a contiguous block.

Specifically, for a sequence, there are four operations:

  • L x y p: Ask for the value of lcm\operatorname{lcm} of numbers in the range [x,y][x,y] modulo pp.
  • G x y p: Ask for the value of gcd\gcd of numbers in the range [x,y][x,y] modulo pp.
  • C x y c: Change all numbers in the range [x,y][x,y] to cc.
  • S x y p: Ask for the number of common divisors of the numbers in the range [x,y][x,y], then take it modulo pp.

The princess must not fail the monthly exam, or she won't be able to study OI (just kidding), so please help her!

Input Format

The first line contains two positive integers nn and qq, where nn is the number of questions and qq is the number of operations.

The second line contains nn positive integers, representing the princess’s estimated values for the questions.

The next qq lines each contain one operation; see the Description for the format.

Output Format

For each query, output its answer.

10 10
42 68 35 1 70 25 79 59 63 65 
L 2 6 28
L 2 6 43
G 2 7 5
G 3 4 83
L 7 9 96
G 2 7 39
S 3 8 100
L 4 5 12
G 4 4 65
L 2 4 69
0
32
1
1
75
1
1
10
1
34

Hint

Constraints

  • For 30%30\% of the testdata, 1n,q10001 \le n, q \le 1000.
  • For another 20%20\% of the testdata, 1n10001 \le n \le 1000, 1q1051 \le q \le 10^5.
  • For another 20%20\% of the testdata, 1n1051 \le n \le 10^5, 1q1051 \le q \le 10^5, and there are no update operations.
  • For 100%100\% of the testdata, 1n3×1051 \le n \le 3 \times 10^5, 1q3×1051 \le q \le 3 \times 10^5.

At any time, each question’s estimated value is in [1,100][1, 100], and each answer after taking modulo fits in int.

Translated by ChatGPT 5