AmazonOA #331
Can Rearrange Binary String
估计中等可在线判题
One operation picks any subsequence of the string, sorts the chosen characters in ascending order, and puts them back into the same chosen positions. For each target string of the same length containing 0/1/?, determine whether every ? can be replaced with 0 or 1 so that the original binary string reaches it after zero or more operations. Each target starts independently from the original string.
输入格式
The first line contains the length L and the number of queries q, the second line contains binary, and the next q lines contain the targets. On this site 1≤L,q≤200000, every target has length L, and the total number of target characters is L×q≤2000000. Only sorting is allowed, not arbitrary swaps.
输出格式
Output YES or NO for each query in order, separated by spaces.
样例 1
输入:
6 2
101100
?110?1
111???
输出:
YES NO
样例 2
输入:
2 2
01
10
??
输出:
NO YES
样例 3
输入:
2 2
11
0?
??
输出:
NO YES
样例说明
The answers are YES NO; NO YES; and NO YES. In the original example, going from 101100 to 011100 should sort the 0-based positions {0,1}, not {0,2} as the original explanation says. The source only compares the total number of 1s, so it would wrongly accept 111???.