luogu#P10863. [HBCPC2024] Enchanted

[HBCPC2024] Enchanted

题目描述

In Minecraft, one way to become stronger is to have the armors and weapons enchanted. Enchanted books play an important role.

The most important attribute of an enchanted book is its level. The higher the level is, the better the book is. We could merge two books with the same level ll into one new book(the older two will disappear). The level of the new book is l+1l+1 and the merger costs 2l+12^{l+1}.

Now, Steve has nn enchanted books numbered from 11 to nn. Initially, the ii-th book's level is aia_i. Steve asks you to help him with the following four operations.

  1. Given two integers l,r(1lrn)l,r(1 \le l \le r \le n), calculate the maximum level Steve can reach by merging books numbered from ll to rr.

  2. Given three integers l,r(1lrn)l,r(1 \le l \le r \le n) and kk, then follow the steps:
    Step 11: Steve merges all the books numbered from ll to rr until there does not exist two books with the same level.
    Step 22: Steve adds one new book with level kk to the books he gets in Step 11.
    Step 33: Steve needs to merge books he gets in Step 22 and he wants to maximize the times he merges the books.
    Please calculate and output the total cost modulo 109+710^9+7 in Step 33.
    $\textbf{Note that, after calculating, the sequence is restored. That is, this operation does NOT actually change the sequence.}$

  3. Given two integers pos,kpos,k, Steve changes the level of the book numbered pospos to kk.

  4. Given one integer tt, Steve restores the sequence to the state after the tt-th operation. If t=0t=0, then Steve restores the sequence to the beginning state.

输入格式

The first and the only line contains 5 integers n,m,A,p,qn,m,A,p,q.(1n1061 \leq n \leq 10^6, 1m1061 \leq m \leq 10^6, 1A192608171 \leq A \leq 19\,260\,817, 1p41 \leq p \leq 4, 1q301 \leq q \leq 30)

Please pay attention! To avoid large input file, the true input is constructed through the following strategy:

$\textbf{Function rnd():}\ \ \ \\ A \leftarrow (7A+13) \bmod 19\,260\,817\ \ \ \\ \textbf{return } A$

Firstly, nn integers a1,a2,,ana_1,a_2,\cdots,a_n are generated in turn, airnd()modq+1a_i \leftarrow rnd() \bmod q + 1.

Then, the parameters of all operations are generated.

For each operation, the number of operation(representing by optopt) is firstly generated, optrnd()modp+1opt \leftarrow rnd() \bmod p + 1.

According to the number of operation, the different method is applied to generate parameters for different operation.

  • For operation 1: we need to get ll and rr by using:

    • Lrnd()modn+1L \leftarrow rnd() \bmod n + 1
    • Rrnd()modn+1R \leftarrow rnd() \bmod n + 1
    • lmin(L,R)l \leftarrow \min(L,R)
    • rmax(L,R)r \leftarrow \max(L,R)
  • For operation 2: we need to get l,rl,r and kk by using:

    • Lrnd()modn+1L \leftarrow rnd() \bmod n + 1
    • Rrnd()modn+1R \leftarrow rnd() \bmod n + 1
    • lmin(L,R)l \leftarrow \min(L,R)
    • rmax(L,R)r \leftarrow \max(L,R)
    • krnd()modq+1k \leftarrow rnd() \bmod q + 1
  • For operation 3: we need to get pospos and kk by using:

    • posrnd()modn+1pos \leftarrow rnd() \bmod n + 1
    • krnd()modq+1k \leftarrow rnd() \bmod q + 1
  • For operation 4: we need to get tt by using:

    • trnd()modit \leftarrow rnd() \bmod i

Here, ii represents the ii-th operation.

输出格式

For each operation 1 and 2, you need to output one single line with an integer, representing the answer to operation 1 and 2 modulo 109+710^9 + 7.

6 3 2 1 3
1
3
2
10 15 5 4 7
0
9
9
0
64
0
0

提示

Function max means the maximum one between the parameters. Function min means the minimum one between the parameters.

In example 1, the initial books are [1,2,3,1,2,3][1,2,3,1,2,3]. The three operations' ranges are [4,4][4,4], [1,3][1,3] and [4,5][4,5].