#P7131. 「RdOI R1」变换(turn)

「RdOI R1」变换(turn)

Description

There are nn transformations. The ii-th transformation has two attributes pip_i and qiq_i. When this transformation is applied to xx, xx becomes fi(x)f_i(x). The definition of fi(x)f_i(x) is:

$$f_i(x)=\left\lfloor\dfrac{x}{p_i}\right\rfloor+q_i$$

You are given mm operations. There are two types of operations:

A modify operation can change the attribute values of a transformation.

A query operation gives xx and two indices ss and tt. You need to compute and output:

ft(ft1(fs+1(fs(x))))f_{t}(f_{t-1}(\cdots f_{s+1}(f_{s}(x))))

Input Format

The first line contains two positive integers nn and mm.

The second line contains nn integers, representing p1,p2,,pnp_1,p_2,\cdots,p_n.

The third line contains nn integers, representing q1,q2,,qnq_1,q_2,\cdots,q_n.

The next mm lines each describe one operation:

A modify operation starts with the letter m, followed by three parameters i,p,qi,p',q', meaning to modify the ii-th transformation’s attributes to p,qp',q'. It is guaranteed that at any time the attributes satisfy 1pi1000,0qi10001\leq p_i\leq 1000, 0\leq q_i\leq 1000.

A query operation starts with the letter q, followed by three parameters x,s,tx,s,t. The meaning is as described above. It is guaranteed that st,0x106s\leq t, 0\leq x\leq 10^6.

Output Format

For each query operation, output one integer, the required answer, separated by newlines.

3 3
2 1 2
1 1 1
q 100 1 3
m 2 2 0
q 100 1 3
27
13
见附件中的 turn-big-sample1.in
见附件中的 turn-big-sample1.out

Hint

Constraints

  • For 20%20\% of the testdata, 1n103,1m1041 \le n \le 10^3,1 \le m \le 10^4.
  • For another 30%30\% of the testdata, 1n104,1m1051 \le n \le 10^4,1 \le m \le 10^5.
  • For 100%100\% of the testdata, 1n105,1m2×1051 \le n \le 10^5,1 \le m \le 2 \times 10^5.

File Input/Output (for simulation; not needed when submitting code)

  • Filename: turn.cpp
  • Input filename: turn.in
  • Output filename: turn.out

Translated by ChatGPT 5