#P11012. [2016杭电多校]Helter Skelter
[2016杭电多校]Helter Skelter
Helter Skelter
Problem Description
A non-empty string is called binary, if it consists only of characters "0" and "1". A substring of string (where is the length of string ) is string . Professor Zhang has got a long binary string starting with "0", and he wants to know whether there is a substring of the string that the occurrences of "0" and "1" in the substring is exact and , respectively, where and are two given numbers. Since the binary string is very long, we will compress it. The compression method is:
- Split the string to runs of same characters.
- Any two adjacent runs consist of different characters. Use the length of each run to represent the string. For example, the runs of a binary string 00101100011110111101001111111 are {00, 1, 0, 11, 000, 1111, 0, 1111, 0, 1, 00, 1111111}, so it will be compressed into {2, 1, 1, 2, 3, 4, 1, 4, 1, 1, 2, 7}.
Input
There are multiple test cases. The first line of input contains an integer , indicating the number of test cases. For each test case: The first line contains two integers and - the number of runs and the number of queries. The next line contains integers: , indicating the length of the each run. Each of the following lines contains two integers and , which means Professor Zhang wants to know whether there is a substring of the string that the occurrences of "0" and "1" in the substring is exact and .
Output
For each test case, a binary string of length . The -th number is "1" if the answer for the -th query is yes, or "0" otherwise.
Sample Input
3
2 3
3 4
3 0
3 4
1 2
3 4
1 2 3
5 1
4 2
1 3
3 2
12 10
2 1 1 2 3 4 1 4 1 1 2 7
2 1
2 2
2 3
2 4
2 5
4 1
4 2
4 3
4 4
4 5
Sample Output
111
0101
1111101111
Author
zimpha
Source
2016 Multi-University Training Contest 2