logo AlgoBeat OnlineJudge
登录 注册

#210693. [HBCPC2024] Enchanted

内存限制:1024 MiB 时间限制:1500 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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 into one new book(the older two will disappear). The level of the new book is and the merger costs .

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

  1. Given two integers , calculate the maximum level Steve can reach by merging books numbered from to .

  2. Given three integers and , then follow the steps:
    Step : Steve merges all the books numbered from to until there does not exist two books with the same level.
    Step : Steve adds one new book with level to the books he gets in Step .
    Step : Steve needs to merge books he gets in Step and he wants to maximize the times he merges the books.
    Please calculate and output the total cost modulo in Step .

  3. Given two integers , Steve changes the level of the book numbered to .

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

输入格式

The first and the only line contains 5 integers .(, , , , )

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

Firstly, integers are generated in turn, .

Then, the parameters of all operations are generated.

For each operation, the number of operation(representing by ) is firstly generated, .

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

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

  • For operation 2: we need to get and by using:

  • For operation 3: we need to get and by using:

  • For operation 4: we need to get by using:

Here, represents the -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 .

样例

样例输入 1

6 3 2 1 3

样例输出 1

1
3
2

样例输入 2

10 15 5 4 7

样例输出 2

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 . The three operations' ranges are , and .