Subsequence Count

来源:互联网 发布:淘宝上的台式机 编辑:程序博客网 时间:2024/06/05 05:59

Subsequence Count

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Given a binary string S[1,...,N] (i.e. a sequence of 0's and 1's), and Q queries on the string.

There are two types of queries:

1. Flipping the bits (i.e., changing all 1 to 0 and 0 to 1) between l and r (inclusive).
2. Counting the number of distinct subsequences in the substring S[l,...,r].
 

Input
The first line contains an integer T, denoting the number of the test cases.

For each test, the first line contains two integers N and Q.

The second line contains the string S.

Then Q lines follow, each with three integers type,l and r, denoting the queries.

1T5

1N,Q105

S[i]{0,1},1iN

type{1,2}

1lrN
 

Output
For each query of type 2, output the answer mod (109+7) in one line.
 

Sample Input
24 410102 1 42 2 41 2 32 1 44 400001 1 21 2 31 3 42 1 4
 

Sample Output
116810
原创粉丝点击