8984: 0 and 1 in BIT

内存限制:128 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:0

题目描述


There are many 000 and 111 in both bit and BIT.

In BIT, the definition of 000 and 111 is also somehow ambiguous. 000 can sometimes become 111 and vice versa.

Now, given an event string containing only AAA and BBB with length nnn, you're required to answer QQQ questions (lreal,rreal,x)(l_{real},r_{real},x)(lreal,rreal,x) which ask what will binary string xxx be after experiencing the events in interval [lreal,rreal][l_{real},r_{real}][lreal,rreal] (The leftmost bit is the most significant bit for xxx).

Here's the illustration for the event AAA, BBB.

AAA: change 000 in xxx to 111 and change 111 in xxx to 000 simultaneously.

BBB: execute x=x+1x=x+1x=x+1 where xxx is viewed as an integer in binary representation. Specially, if xxx contains only 111, xxx will become a binary string with all 000.

You are required to answer each problem online. For this propose, if we ask (l,r)(l,r)(l,r) in the i−i-ith query, it means the actually asked segment is defined as:

lreal=min((ansi−1⊕l)%n+1, (ansi−1⊕r)%n+1)l_{real} = min((ans_{i-1}\oplus l)\%n+1,\ (ans_{i-1}\oplus r)\%n+1)lreal=min((ansi1l)%n+1, (ansi1r)%n+1)

rreal=max((ansi−1⊕l)%n+1, (ansi−1⊕r)%n+1)r_{real} = max((ans_{i-1}\oplus l)\%n+1,\ (ans_{i-1}\oplus r)\%n+1)rreal=max((ansi1l)%n+1, (ansi1r)%n+1)

where ⊕\oplus is the exclusive OR operation and ansi−1ans_{i-1}ansi1 is the answer for the (i−1)−(i-1)-(i1)th query (viewed as an integer in binary representation) with ans0=0ans_0=0ans0=0.

输入格式

The first line contains two integers, n(3≤n≤2×105),q(1≤q≤2×105)n(3\leq n\leq 2\times 10^5),q(1\leq q\leq 2\times 10^5)n(3n2×105),q(1q2×105), the length of event string and the number of queries.
The second line contains the event string S(∣S∣=n)S(|S|=n)S(S=n) and SSS contains only AAA and BBB.
In the following qqq lines, each line contains a query l,r,x(1≤l≤r≤n,1≤∣x∣≤50)l,r,x(1\leq l\leq r\leq n, 1\leq |x| \leq 50)l,r,x(1lrn,1x50), and xxx is a binary string containing only 000 and 111.

输出格式


For each query, output the binary representation of xxx after the events in interval [l,r][l,r][l,r].

输入样例 复制

10 3
BAABABABBA
1 8 0001
3 5 110
6 10 0101010101

输出样例 复制

0011
111
0101010110

数据范围与提示


The actually asked segments in the samples are (2,9),(1,7),(2,4)(2,9),(1,7),(2,4)(2,9),(1,7),(2,4), respectively.

分类标签