#P10626. IOI Function Evaluation
IOI Function Evaluation
IOI Function Evaluation
JOI-kun studies at IOI High School and faces a final exam on computing the IOI Function. An IOI function maps each integer in the interval \([1,10^9]\) to a Boolean value (i.e. True
or False
). It is built using the following six rules:
- Base: For an integer \(a\) in \([1,10^9]\), the expression
[a]
is an IOI function. It maps any integer \(x\) toTrue
if \(x \ge a\) andFalse
otherwise. - Parentheses: If
f
is an IOI function, then(f)
is also an IOI function. Its mapping is identical to that off
. - Negation: If
f
is an IOI function, then!f
is also an IOI function. For an integer \(x\), iff(x)
=True
then!f(x)
=False
; otherwise,!f(x)
=True
. - AND: If
f
andg
are IOI functions, thenf&g
is an IOI function. For an integer \(x\),f&g
returnsTrue
if and only if bothf(x)
andg(x)
areTrue
. - XOR: If
f
andg
are IOI functions, thenf^g
is an IOI function. For an integer \(x\),f^g
returnsTrue
if and only if exactly one off(x)
andg(x)
isTrue
. - OR: If
f
andg
are IOI functions, thenf|g
is an IOI function. For an integer \(x\),f|g
returnsTrue
if and only if at least one off(x)
org(x)
isTrue
.
If an IOI function can be built in several ways, the rule with the largest rule number determines the mapping. For example, [1]&[2]|[3]
should be interpreted as ([1]&[2])|[3]
(using rule 6 for |
) rather than [1]&([2]|[3])
. Furthermore, for rules 4, 5, and 6, the left part (f
) should be maximized. For instance, [4]^ [5]^ [6]
is parsed as ([4]^ [5])^ [6]
(applying rule 5 with f = [4]^ [5]
rather than f = [4]
).
JOI-kun has prepared an IOI function S
of length \(N\) for his practice. He will use \(Q\) integers \(X_1, X_2, \dots, X_Q\) to test his computation skills. Your task is to help him compute the value of the IOI function S
for each integer \(X_i\): output True
or False
accordingly.
inputFormat
The input is given in the following format:
N Q S X_1 X_2 ... X_Q
Here,
- \(N\) is the length of the string representing the IOI function \(S\).
- \(Q\) is the number of queries.
- \(S\) is the IOI function expressed as a string consisting of tokens
[a]
,!
,&
,^
,|
, and parentheses(
and)
. - Each \(X_i\) is an integer query (\(1 \le X_i \le 10^9\)).
outputFormat
Output \(Q\) lines. The \(i\)-th line should be True
if the IOI function \(S\) maps \(X_i\) to True
and False
otherwise.
sample
5 3
[10]
5
10
15
False
True
True
</p>