Alternating 2.0
时间限制:C/C++/Rust/Pascal 4秒,其他语言8秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述

Let's call a binary string (a string where each character is either 0 or 1) x of length k an alternating string if and only if for all .

You can perform the following operation on a binary string x of length k:

  • Choose a substring and invert all characters of this substring, that is, replace 0 by 1 and vice versa.

Let's call beauty of a binary string x the minimum number of operations that need to be performed on x to make it an alternating string.

Now you are given a binary string s of length n.

You need to support q queries. Each query is represented by two indices l and r, denoting that you have to calculate the sum of beauty of all non-empty subsequences of modulo .

The queries are given in a compressed format. Let l_i and r_i be the bounds for the i-th query. For , let and . If , they are swapped. Then assign f to l_i and g to r_i. The value of a_l,b_l,a_r,b_r,l_0,r_0 will be given in the input.

Let ans_i be the answer modulo to the i-th query. You need to output .

Here, denotes the bitwise XOR operation.

String x is a subsequence of string y if and only if x can be obtained from y by deletion of several (possibly, zero) characters.

输入描述:

The first line contains two integers n,q () --- the length of the binary string s and the number of queries.

The second line contains a binary string s of length n.

The third line contains six integers a_l,b_l,a_r,b_r,l_0,r_0 () --- the parameters to generate the queries.

输出描述:

Print a single integer --- the value of .
示例1

输入

复制
3 2
001
0 0 1 0 1 1

输出

复制
40

说明

In the first query, l_1 = 1,r_1 = 2,s_1s_2 = 00, all non-empty subsequences of 00 are 0,0,00, beauty of which are 0,0,1 respectively, with the sum of 0 + 0 + 1 = 1.

In the second query, l_2 = 1,r_2 = 3,s_1s_2s_3 = 001, all non-empty subsequences of 001 are 0,0,1,00,01,01,001, beauty of which are 0,0,0,1,0,0,1 respectively, with the sum of 0 + 0 + 0 + 1 + 0 + 0 + 1 = 2.

Thus, \bigoplus\limits_{i = 1}^q (ans_i + 23 \cdot i) = (1 + 23 \cdot 1) \oplus (2 + 23 \cdot 2) = 40.