Examination 2

시간 제한2초메모리 제한1024 MB

요약
연산자 우선순위와 좌결합 규칙을 가진 문자열 S가 정의하는 IOI 함수에 대해, Q개의 정수 X_i 각각에 대한 참·거짓 값을 판정한다.
난이도

보통10점 중 6점

유형
스택, 문자열, 구현, 정렬
정답자
아직 제출이 없습니다

문제

JOI-kun goes to IOI High School, where the final exam is held soon. In the exam, students will be tested on whether they can correctly calculate the value of an IOI function. An IOI function is a string obtained by one of the following six rules defined by IOI High School, which maps integers between 11 and 10910^9 (inclusive) to boolean values, either True or False.

  1. Let aa be an integer between 11 and 10910^9 (inclusive), then [a] is an IOI function (a is the string representation of aa in decimal notation). This IOI function maps integers greater than or equal to aa to True, and integers less than aa to False.
  2. Let f be an IOI function, then (f) is also an IOI function. This IOI function maps the same integers to True and False as f does.
  3. Let f be an IOI function, then !f is also an IOI function. This IOI function maps integers that f maps to True to False, and vice versa.
  4. Let f and g be IOI functions, then f&g is also an IOI function. This IOI function maps integers to True if both f and g map them to True, and to False otherwise.
  5. Let f and g be IOI functions, then fˆg is also an IOI function. This IOI function maps integers to True if exactly one of f or g maps them to True, and to False otherwise.
  6. Let f and g be IOI functions, then f|g is also an IOI function. This IOI function maps integers to True if at least one of f or g maps them to True, and to False otherwise.

If an IOI function is obtained using multiple rules, the rule with the higher number determines the boolean value that the IOI function maps integers to. For example, for [1]&[2]|[3], rule 6 is applied to f = [1]&[2] and g = [3] (rather than applying rule 4 to f = [1] and g = [2]|[3]). Additionally, for rules 4, 5, and 6, the rule is applied so that f becomes as long as possible. For example, for [4]ˆ[5]ˆ[6], rule 5 is applied to f = [4]ˆ[5] and g = [6] (rather than applying rule 5 to f = [4] and g = [5]ˆ[6]).

To prepare for the exam, JOI-kun has prepared an IOI function SS of length NN and intends to practice determining the boolean values that this IOI funcition maps QQ integers X_1,X_2,…,X_QX\_1, X\_2, \dots , X\_Q to. He askes for your help, as you are proficient with handling IOI functions, to create a sample solution.

Write a program which, given NN, QQ, SS and X_1,X_2,…,X_QX\_1, X\_2, \dots , X\_Q, determines the boolean values that the IOI function SS maps integers X_1,X_2,…,X_QX\_1, X\_2, \dots , X\_Q to.

입력

The input is given from Standard Input in the following format:

NN QQ

SS

X_1X\_1

X_2X\_2

⋮\vdots

X_QX\_Q

출력

Print QQ lines to Standard Output. ii-th line (1≤i≤Q1 ≤ i ≤ Q) should contain a single boolean value which the IOI function SS maps the integer X_iX\_i to.

제한

  • 1≤N≤1,000,0001 ≤ N ≤ 1\\, 000\\, 000.
  • 1≤Q≤200,0001 ≤ Q ≤ 200\\, 000.
  • SS is an IOI function of length NN.
  • 1≤X_i≤1091 ≤ X\_i ≤ 10^9 (1≤i≤Q1 ≤ i ≤ Q).
  • NN, QQ, and X_iX\_i (1≤i≤Q1 ≤ i ≤ Q) are integers.

예제3

  1. 예제 1

    입력
    15 5
    (![2]|[3])&![4]
    1
    2
    3
    4
    5
    
    예상 출력
    True
    False
    True
    False
    False
    
  2. 예제 2

    입력
    20 4
    (!![23])ˆ((([116])))
    54
    1
    200
    89
    
    예상 출력
    True
    False
    False
    True
    
  3. 예제 3

    입력
    32 4
    [2]|[5]&[1]|(([1000000000])|[7])
    4
    10
    6
    1
    
    예상 출력
    True
    True
    True
    False