luogu#P10399. 『STA - R5』ReLyna

『STA - R5』ReLyna

Background

Problem Description

You have a number xx in your hand. When you arrive at position ii, you may change the number in your hand to x+aix+a_i or x×bix\times b_i.

There are mm operations.

  • 1 x y z: set axya_x\gets y, bxzb_x\gets z.

  • 2 l r: query the following. If you choose a subsegment [l,r][l',r'] uniformly at random from all subsegments of [l,r][l,r], what is the expected value of the maximum possible number in your hand after you walk from ll' to rr'? Output the answer modulo 109+710^9+7. Before each walk starts, the number in your hand is reset to 00.

If you do not know how to take a rational number modulo a prime, you may refer to P2613 Taking Remainder of Rational Numbers.

You may use the sample explanation to better understand the statement.

Input Format

The first line contains two integers n,mn,m.

The second line contains nn integers, where the ii-th integer denotes aia_i.

The third line contains nn integers, where the ii-th integer denotes bib_i.

The next mm lines each describe one operation. The format is given in the description.

Output Format

For each query, output the corresponding expectation. The answer should be taken modulo 109+710^9+7.

5 4
48 52 8 27 34 
3 4 3 2 2 
2 2 3
2 1 5
1 1 34 4
2 1 3

72
133333711
333333468

Hint

Sample Explanation

For the first query, let f(i,j)f(i,j) be the maximum possible number in your hand after you start from ii and walk sequentially to jj. Then the answer is $\frac{1}{3}[f(2,2)+f(2,3)+f(3,3)]=\frac{1}{3}(52+156+8)=72$.

Constraints

Subtask ID nn mm Special Property Score
Subtask #1 5050 None 5
Subtask #2 500500
Subtask #3 10510^5 10510^5 Guaranteed that at any time ai=1a_i=1 25
Subtask #4 5050 None
Subtask #5 10510^5 No modification operations
Subtask #6 None 15

For all testdata, 1n,m1051\le n,m\le 10^5, 0<ai<109+70<a_i<10^9+7, 1<bi<109+71<b_i<10^9+7. All operations are guaranteed to be valid, and all inputs are guaranteed to be integers.

Translated by ChatGPT 5