#P3814. [FJOI2017] 远古山脉问题
[FJOI2017] 远古山脉问题
Description
An ancient mountain range can be regarded as a sequence of mountain elements, each with a height. The evolution rules are as follows:
- I h x: Insert a mountain element of height to the right of the -th mountain element.
- R l r: Reverse the heights of the mountain elements from the -th to the -th. For example, , reversing becomes .
- M t x: Insert the -th mountain to the right of the -th mountain element.
Mountain elements are numbered from from left to right. Initially there are no mountain elements, denoted as the -th mountain. For the -th mountain, after applying any one operation it becomes the -th mountain. The mountain collects energy as follows: suppose the index of the highest mountain element is . If there are elements with the same maximum height, take the -th one from the left. Then the collected energy is:
$$\sum_{i=l}^{x-1}\left\{\begin{matrix} x-i & if\ h_{i}>h_{i+1}\\ 0 & if\ h_{i}\leq h_{i+1} \end{matrix}\right.+\sum_{i=x+1}^{r}\left\{\begin{matrix} i-x & if\ h_{i}>h_{i-1}\\ 0 & if\ h_{i}\leq h_{i-1} \end{matrix}\right.$$Here denotes the height of the -th mountain element.
The basic query to answer is: for the sub-mountain formed by the mountain elements from the -th to the -th, how much energy can be collected?
Input Format
The first line contains a positive integer (), the total number of operations and queries.
Then follow lines, each in one of the following four formats:
- I h x: Insert a mountain element of height to the right of the -th mountain element, .
- R l r: Reverse the heights from the -th mountain element to the -th mountain element.
- M t x: Insert the -th mountain to the right of the -th mountain element.
- Q l r: Query the energy collected by the sub-mountain formed by the -th to the -th mountain elements.
For the -th mountain, after applying any one operation it becomes the -th mountain.
All input integers fit in the range of long long.
Output Format
For each query, output the answer on one line, modulo 1000000007.
10
I 1 0
I 2 1
I 3 1
Q 1 3
I 4 3
Q 1 4
R 2 4
Q 1 4
M 3 4
Q 2 7
0
2
2
6
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号