#P11283. 「GFOI Round 2」Turtle and Nediam
「GFOI Round 2」Turtle and Nediam
Description
For a sequence of distinct positive integers with length , the "nediam" is defined as follows:
- When , is the median of ;
- When , for any contiguous subsequence of length denoted as , let the median of this subsequence be . The sequence obtained by removing from is denoted as , and is the maximum value of over all such subsequences.
Turtle gives you a permutation of the integers from to and queries. For each query, given and , you need to calculate the "nediam" .
Input Format
To speed up the input process, we will use the following method.
The first line contains six positive integers .
The second line contains a permutation .
For the next queries, you will generate the pair as follows:
unsigned seed, A, B, C;
inline unsigned rnd() {
seed = A * seed * seed + B * seed + C;
seed = seed ^ (seed << 27);
seed = seed ^ (seed >> 19);
return seed;
}
inline std::pair<int, int> gen() {
int l, r;
do {
l = rnd() % n + 1;
r = rnd() % n + 1;
} while (abs(l - r) < 2);
if (l > r) {
std::swap(l, r);
}
return std::make_pair(l, r);
}
For each query, call gen() once to generate the pair for that query.
Output Format
To speed up the output process, we will use the following method.
Let the answer for the -th query be . You need to output $(1 \times ans_1) \oplus (2 \times ans_2) \oplus \cdots \oplus (m \times ans_m)$, where denotes the bitwise XOR operation.
4 4 114 514 1919 810
1 3 4 2
1
10 100 123456 789123 456789 123456789
3 9 5 7 6 4 10 8 2 1
142
Hint
Sample Explanation
The generated four queries are , with answers respectively. Therefore, you need to output $(1 \times 2) \oplus (2 \times 3) \oplus (3 \times 3) \oplus (4 \times 3) = 2 \oplus 6 \oplus 9 \oplus 12 = 1$.
For the first query, choosing the contiguous subsequence or will result in the deletion of . After removing , the remaining sequence is , and the median is .
Subtasks and Constraints
| Subtask ID | Special Properties | Score | ||
|---|---|---|---|---|
| No | ||||
| A | ||||
| No | ||||
| B | ||||
| No | ||||
- Special Property A: .
- Special Property B: is randomly generated with equal probability from all permutations of .
For all tests, it is guaranteed that:
- ;
- ;
- ;
- is a permutation of .
京公网安备 11011102002149号