#P8055. B Highbit & lowbit
B Highbit & lowbit
Description
Define the of a positive integer as the value of its highest binary bit in its binary representation. For example, $\mathrm{highbit}(22_{(10)})=\mathrm{highbit}(10110_{(2)})=10000_{(2)}=16_{(10)}$.
Define the of a positive integer as the value of its lowest non-zero binary bit in its binary representation. For example, $\mathrm{lowbit}(22_{(10)})=\mathrm{lowbit}(10110_{(2)})=10_{(2)}=2_{(10)}$.
Define two operations:
- Operation : change a positive integer into .
- Operation : change a positive integer into .
Now you are given an operation sequence and queries. Each query contains positive integers , meaning that starting from left to right, apply operations to in order. Output the final value of . Since the answer may be very large, output the result modulo .
Input Format
The first line contains two positive integers .
The next line contains a string of length , consisting only of 0 and 1.
If the -th character is 0, it represents an Operation , i.e. .
If the -th character is 1, it represents an Operation , i.e. .
Then follow lines. Each line contains positive integers , representing one query.
Output Format
For each query, output one line with one number, the answer modulo .
8 8
01100001
1 2 3
1 4 9
2 6 9
3 8 9
6 8 2
8 8 3
5 8 6
2 8 17
8
36
40
64
16
5
64
144
Hint
Constraints
This problem uses bundled testdata.
For all test cases, , . The detailed constraints are as follows:
- Subtask #1 (12 pts): , .
- Subtask #2 (23 pts): .
- Subtask #3 (11 pts): , the string contains only
1. - Subtask #4 (11 pts): , the string contains only
0. - Subtask #5 (6 pts): , it is guaranteed that in every query, can be written as , where is a non-negative integer.
- Subtask #6 (15 pts): , it is guaranteed that in every query, can be written as , where are non-negative integers.
- Subtask #7 (10 pts): .
- Subtask #8 (12 pts): No additional constraints.
Translated by ChatGPT 5
京公网安备 11011102002149号