luogu#P10399. 『STA - R5』ReLyna
『STA - R5』ReLyna
Background

Problem Description
You have a number in your hand. When you arrive at position , you may change the number in your hand to or .
There are operations.
-
1 x y z: set , . -
2 l r: query the following. If you choose a subsegment uniformly at random from all subsegments of , what is the expected value of the maximum possible number in your hand after you walk from to ? Output the answer modulo . Before each walk starts, the number in your hand is reset to .
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 .
The second line contains integers, where the -th integer denotes .
The third line contains integers, where the -th integer denotes .
The next 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 .
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 be the maximum possible number in your hand after you start from and walk sequentially to . 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 | Special Property | Score | ||
|---|---|---|---|---|
| Subtask #1 | None | 5 | ||
| Subtask #2 | ||||
| Subtask #3 | Guaranteed that at any time | 25 | ||
| Subtask #4 | None | |||
| Subtask #5 | No modification operations | |||
| Subtask #6 | None | 15 | ||
For all testdata, , , . All operations are guaranteed to be valid, and all inputs are guaranteed to be integers.
Translated by ChatGPT 5