Helter Skelter
Time limit2sMemory limit128 MB
Given the run lengths of a binary string that starts with 0, answer for each query whether some substring has exactly a zeros and b ones.
- Level
Hard8 of 10
- Topics
- Two pointers, Prefix sum, Math
- Solved
- No attempts yet
Problem
A non-empty string is called a binary string if it consists only of the characters '0' and '1'. A substring of a string is the string .
Professor Zhang has a long binary string that starts with '0'. He wants to know whether has a substring with exactly zeros and exactly ones, where and are two given integers.
The string is very long, so it is compressed as follows.
- Split the string into runs of equal consecutive characters.
- Any two adjacent runs consist of different characters. Write the length of each run to represent the string.
For example, the runs of the binary string 00101100011110111101001111111 are , so it is compressed into .
Input
The first line contains an integer , 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 (), the length of each run.
Each of the following lines contains two integers and (, ). For each query, determine whether has a substring with exactly zeros and exactly ones.
There are at most 200 test cases, and the total input size is at most 20 mebibytes. The sum of over all test cases is at most .
Output
For each test case, print a binary string of length . The -th digit is '1' if the answer to the -th query is yes, and '0' otherwise.