Helter Skelter

아직 제출이 없습니다시간 제한2초메모리 제한128 MB

문제

A non-empty string ss is called a binary string if it consists only of characters '0' and '1'. A substring s\[lr]s\[l \ldots r] (1lrs)(1 \le l \le r \le |s|) of string s=s_1s_2s_ss = s\_{1} s\_{2} \ldots s\_{|s|} (where s|s| is the length of string ss) is the string s_ls_l+1s_rs\_{l} s\_{l + 1} \ldots s\_{r}.

Professor Zhang has got a long binary string ss starting with '0', and he wants to know whether there is a substring of ss such that the number of occurrences of '0' and '1' in this substring are exactly aa and bb, respectively, where aa and bb are two given integers.

Since the binary string is very long, we will compress it. The compression method is as follows:

  • Split the string into runs of equal consecutive characters.
  • Any two adjacent runs consist of different characters. Use the length of each run to represent the string.

For example, the runs of the binary string "00101100011110111101001111111" are 00,1,0,11,000,1111,0,1111,0,1,00,1111111\\{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\\{2, 1, 1, 2, 3, 4, 1, 4, 1, 1, 2, 7\\}.

입력

There are multiple test cases. The first line of input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (1n10001 \le n \le 1000, 1m51051 \le m \le 5 \cdot 10^5): the number of runs and the number of queries. The next line contains nn integers: x_1,x_2,,x_nx\_1, x\_2, \ldots, x\_n (1x_i1061 \le x\_i \le 10^6) indicating the length of each run.

Each of the following mm lines contains two integers a_ia\_i and b_ib\_i (0a_i,b_is0 \le a\_i, b\_i \le |s|, 1a_i+b_is1 \le a\_i + b\_i \le |s|) which means that Professor Zhang wants to know whether there is a substring of ss such that the number of occurrences of '0' and '1' in this substring are exactly a_ia\_i and b_ib\_i, respectively.

There are no more than 200200 test cases, and the total size of the input is at most 2020 mebibytes. Additionally, the sum of mm in all test cases is at most 21062 \cdot 10^{6}.

출력

For each test case, print a binary string of length mm. The ii-th digit must be '1' if the answer for the ii-th query is "yes", or '0' otherwise.