#P10626. [JOI Open 2024] 考试 2 / Examination 2

    ID: 12101 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP线段树树上启发式合并2024树链剖分动态树 LCTJOI(日本)

[JOI Open 2024] 考试 2 / Examination 2

Problem Description

JOI-kun studies at IOI High School, and the final exams are coming soon. The exam topic is computing the IOI function. An IOI function maps integers in [1,109][1,10^9] to boolean values (i.e., True/False\texttt{True}/\texttt{False}). An IOI function can be constructed using the following six rules specified by IOI High School:

  1. Let aa be an integer in [1,109][1,10^9]. Then [a]\texttt{[a]} is an IOI function. It maps integers not less than aa to True\texttt{True}, and integers less than aa to False\texttt{False}.

  2. Let f\texttt{f} be an IOI function. Then (f)\texttt{(f)} is an IOI function, and its mapping rule is the same as that of f\texttt{f}.

  3. Let f\texttt{f} be an IOI function. Then !f\texttt{!f} is an IOI function. Let xx be an integer. If f\texttt{f} maps xx to True\texttt{True}, then !f\texttt{!f} maps xx to False\texttt{False}; otherwise, !f\texttt{!f} maps xx to True\texttt{True}.

  4. Let f,g\texttt{f},\texttt{g} be IOI functions. Then f&g\texttt{f\&g} is also an IOI function. Let xx be an integer. Then f&g\texttt{f\&g} maps xx to True\texttt{True} if and only if both f\texttt{f} and g\texttt{g} map xx to True\texttt{True}.

  5. Let f,g\texttt{f},\texttt{g} be IOI functions. Then f ˆg\texttt{f\^ g} is also an IOI function. Let xx be an integer. Then f ˆg\texttt{f\^ g} maps xx to True\texttt{True} if and only if exactly one of f\texttt{f} and g\texttt{g} maps xx to True\texttt{True}.

  6. Let f,g\texttt{f},\texttt{g} be IOI functions. Then f|g\texttt{f|g} is also an IOI function. Let xx be an integer. Then f|g\texttt{f|g} maps xx to True\texttt{True} if and only if at least one of f\texttt{f} and g\texttt{g} maps xx to True\texttt{True}.

If an IOI function can be constructed by multiple rules, the rule with the larger number determines the function value. For example, for [1]&[2]|[3]\texttt{[1]\&[2]|[3]}, you should apply rule 6, where f=[1]&[2]\texttt{f} = \texttt{[1]\&[2]} and g=[3]\texttt{g} = \texttt{[3]} (instead of applying rule 4, where f=[1]\texttt{f} = \texttt{[1]} and g=[2]|[3]\texttt{g} = \texttt{[2]|[3]}). In addition, for rules 4, 5, and 6, you should maximize the length of f\texttt{f}. For example, for [4]ˆ[5]ˆ[6]\texttt{[4]ˆ[5]ˆ[6]}, you should apply rule 5 with f=[4]ˆ[5]\texttt{f} = \texttt{[4]ˆ[5]} and g=[6]\texttt{g} = \texttt{[6]} (instead of f=[4]\texttt{f} = \texttt{[4]} and g=[5]ˆ[6]\texttt{g} = \texttt{[5]ˆ[6]}).

To prepare for the final exams, JOI-kun has prepared an IOI function SS of length NN. He plans to practice his computation skills using QQ integers X1,X2,,XQX_1,X_2,\cdots,X_Q. So he asked you, who can skillfully handle IOI functions, to solve this problem.

You need to write a program. Given N,Q,SN,Q,S and X1,X2,,XQX_1,X_2,\cdots,X_Q, for i=1,2,,Qi=1,2,\cdots,Q, answer whether the IOI function SS maps XiX_i to True\texttt{True} or False\texttt{False}.

Input Format

The input format is as follows:

NN QQ
SS
X1X_1
X2X_2
\vdots
XQX_Q

Output Format

Output QQ lines. The ii-th line should be True\texttt{True} or False\texttt{False}, which is the value that SS maps XiX_i to.

15 5
(![2]|[3])&![4]
1
2
3
4
5
True
False
True
False
False
20 4
(!![23])^((([116])))
54
1
200
89
True
False
False
True
32 4
[2]|[5]&[1]|(([1000000000])|[7])
4
10
6
1
True
True
True
False

Hint

Sample Explanation

The explanation for sample 11 is as follows:

XiX_i ![2]\texttt{![2]} [3]\texttt{[3]} ![2]|[3]\texttt{![2]\char124[3]} ![4]\texttt{![4]} (![2]|[3])&![4]\texttt{(![2]\char124[3])\&![4]}
11 True\texttt{True} False\texttt{False} True\texttt{True} True\texttt{True} True\texttt{True}
22 False\texttt{False} False\texttt{False} False\texttt{False}
33 True\texttt{True} True\texttt{True}
44 False\texttt{False}
55

Sample 11 satisfies the conditions of subtasks 3,6,73,6,7.

Sample 22 satisfies the conditions of subtasks 1,3,571,3,5\sim 7.

Sample 33 satisfies the conditions of subtasks 3,4,6,73,4,6,7.

Constraints

  • 1N10000001 \le N \le 1\,000\,000.
  • 1Q2000001 \le Q \le 200\,000.
  • SS is an IOI function of length NN.
  • 1Xi1091 \le X_i \le 10^9 (1iQ1 \le i \le Q).
  • NN, QQ, and XiX_i (1iQ1 \le i \le Q) are all integers.

Subtasks

  1. (55 points) SS does not contain &\texttt{\&} or |\texttt{|}.
  2. (2020 points) Q=1Q = 1.
  3. (1010 points) N10000N \le 10\,000.
  4. (66 points) SS does not contain !\texttt{!} or ˆ\texttt{ˆ}.
  5. (1212 points) When applying rule 4 or 6 to construct SS, at least one of f\texttt{f} and g\texttt{g} is obtained by rule 1.
  6. (2020 points) N400000N \le 400\, 000.
  7. (2727 points) No additional constraints.

*Contest announcement: If you copy the LaTeX in the statement, you might get ˆ, but it is actually ^. Please pay special attention.

Translated from the English statement by Starrykiller.

Translated by ChatGPT 5