#P8055. B Highbit & lowbit

B Highbit & lowbit

Description

Define the highbit\mathrm{highbit} 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 lowbit\mathrm{lowbit} 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 11: change a positive integer xx into x+lowbit(x)x+\mathrm{lowbit}(x).
  • Operation 22: change a positive integer xx into x+highbit(x)x+\mathrm{highbit}(x).

Now you are given an operation sequence and qq queries. Each query contains 33 positive integers l,r,xl,r,x, meaning that starting from left to right, apply operations lrl \sim r to xx in order. Output the final value of xx. Since the answer may be very large, output the result modulo 109+710^9+7.

Input Format

The first line contains two positive integers n,qn,q.

The next line contains a string ss of length nn, consisting only of 0 and 1.

If the ii-th character is 0, it represents an Operation 11, i.e. x=x+lowbit(x)x=x+\mathrm{lowbit}(x).

If the ii-th character is 1, it represents an Operation 22, i.e. x=x+highbit(x)x=x+\mathrm{highbit}(x).

Then follow qq lines. Each line contains 33 positive integers l,r,xl,r,x, representing one query.

Output Format

For each query, output one line with one number, the answer modulo 109+710^9+7.

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, 1n,q5×1051\leq n,q\leq 5\times 10^5, 1x<2301\leq x<2^{30}. The detailed constraints are as follows:

  • Subtask #1 (12 pts): n,q10n,q\le 10, x32767x\le 32767.
  • Subtask #2 (23 pts): n,q103n,q\le 10^3.
  • Subtask #3 (11 pts): n,q105n,q\leq 10^5, the string contains only 1.
  • Subtask #4 (11 pts): n,q105n,q\leq 10^5, the string contains only 0.
  • Subtask #5 (6 pts): n,q105n,q\leq 10^5, it is guaranteed that in every query, xx can be written as 2a2^a, where aa is a non-negative integer.
  • Subtask #6 (15 pts): n,q105n,q\leq 10^5, it is guaranteed that in every query, xx can be written as 2a+2b2^a+2^b, where a,ba,b are non-negative integers.
  • Subtask #7 (10 pts): n,q105n,q\le 10^5.
  • Subtask #8 (12 pts): No additional constraints.

Translated by ChatGPT 5