#P11843. [USACO25FEB] The Best Subsequence G
[USACO25FEB] The Best Subsequence G
Description
Farmer John has a binary string of length , initially all zeros.
He will first perform () updates on the string, in order. Each update flips every character from to . Specifically, flipping a character changes it from to , or vice versa.
Then, he asks you () queries. For each query, he asks you to output the lexicographically greatest subsequence of length comprised of characters from the substring from to . If your answer is a binary string , then output (that is, its value when interpreted as a binary number) modulo .
A subsequence is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.
Recall that string is lexicographically greater than string of equal length if and only if at the first position , if it exists, where , we have .
Input Format
The first line contains , , and .
The next lines contain two integers, and () — the endpoints of each update.
The next lines contain three integers, , , and () — the endpoints of each query and the length of the subsequence.
Output Format
Output lines. The th line should contain the answer for the th query.
5 3 9
1 5
2 4
3 3
1 5 5
1 5 4
1 5 3
1 5 2
1 5 1
2 5 4
2 5 3
2 5 2
2 5 1
21
13
7
3
1
5
5
3
1
9 1 1
7 9
1 8 8
3
30 1 1
1 30
1 30 30
73741816
Hint
For Sample 1:
After performing the operations, the string is .
For the first query, there is only one subsequence of length , , which is interpreted as $1 \cdot 2^4 + 0 \cdot 2^3 + 1 \cdot 2^2 + 0 \cdot 2^1 + 1 \cdot 2^0 = 21$.
For the second query, there are unique subsequences of length : , , , , . The lexicographically largest subsequence is , which is interpreted as $1 \cdot 2^3 + 1 \cdot 2^2 + 0 \cdot 2^1 + 1\cdot 2^0 = 13$.
For the third query, the lexicographically largest sequence is , which is interpreted as .
For Sample 3:
Make sure to output the answer modulo .
SCORING:
- Input 4:
- Input 5:
- Inputs 6-7:
- Inputs 8-12:
- Inputs 13-20: No additional constraints.
京公网安备 11011102002149号