#P3284. [SCOI2014] 方伯伯打扑克
[SCOI2014] 方伯伯打扑克
Description
Uncle Fang has some blank playing cards. He wants to use them to play a math game.
He first decides to form piles from these blank cards, with the size of each pile being an integer power of . Specifically, the -th pile (note: indexed from ) will have cards. He first decides that pile has cards, and then labels the cards in this pile from top to bottom with the decimal numbers in order.
Before starting the game, Uncle Fang decides to shuffle, and he decides to shuffle times. He has a fixed shuffling pattern: each shuffle is equivalent to the following two steps:
- Take out all cards in odd positions (counted from the top) in order to form a new pile.
- Place this new pile on top of the remaining old pile.
For example, when , pile starts from top to bottom as 12345678'', after one shuffle it becomes 13572468'', and after two shuffles it becomes ``15263748''.
After shuffling, Uncle Fang decides to add a number to the labels of the cards from the -th to the -th from top to bottom. He then converts these labels to binary and XORs them in order to obtain a value; he records the value modulo as .
Similarly, Uncle Fang will play with the remaining piles in the same way. Specifically, he decides to operate on each pile according to the following formulas:
- For the -th pile, the pile will have cards, labeled from top to bottom with the decimal integers . Here, $n_i = (\mathrm{ans}_{i-1} + i - 1) \bmod 5 \mathrel{+} \mathrm{Base}$, where is a positive integer decided in advance.
- He first decides the position of the first card he will look at, denoted by , where $l_i = (2\mathrm{ans}_{i-1} + l_{i-1} + i - 1) \bmod 2^{n_i} \mathrel{+} 1$.
- He then decides the position of the last card he will look at, denoted by , where $r_i = \bigl(\mathrm{ans}_{i-1} + 1 + 2^{\lfloor n_i/2 \rfloor}(l_i \bmod 2^{\lfloor n_i/2 \rfloor})\bigr) \bmod 2^{n_i} \mathrel{+} 1$.
- Since the above two formulas are not simple, it is possible that . In that case, swap their values.
- After deciding which cards to look at, he decides to shuffle times, where .
- He also decides the number to add to each selected card, where .
- After shuffling, he adds to each card from the -th to the -th from top to bottom, converts them to binary and XORs them in order to obtain a value; he records the value modulo as , and then returns to Step 1 to play with the next pile.
Uncle Fang has heard about your outstanding informatics skills. He wants to know whether you can compute in advance the game result for the last pile, i.e., pile . Can you do it?
Input Format
The first line contains an integer , the number of piles.
The next line contains six integers: .
Output Format
Output a single integer, the final answer.
2
5 1 4 27 3 15
2700
Hint
Constraints
- For of the testdata, .
- For of the testdata, , , .
- For of the testdata, , , .
- For all testdata, $m \le 5\times 10^6,\ n_i \le 60,\ 0 < l_i \le r_i \le 2^{n_i},\ 0 < x_i, t_i < 10^9,\ \mathrm{Base} \le 55$.
Sample Explanation , , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号