#P7326. 「MCOI-07」Dream and Evaluation

「MCOI-07」Dream and Evaluation

Description

George is studying bitwise operations. He wrote a bitwise expression, but he cannot compute its value efficiently, so he asked Dream to help him compute it.

George's expression has 6464 binary variables, numbered from 00 to 6363. He provides the postfix notation of the expression.

The postfix notation may contain the following symbols:

  • 0,1,,630,1,\dots,63, representing the corresponding variables.
  • !&|^, representing the corresponding bitwise operations.

Now Dream has mm cases. In each case, the values of all 6464 variables are fixed. You need to compute the value of the given expression for each case.

To make input easier, these cases are compressed. Let ai,ja_{i,j} be the value of variable jj in case ii, where ai,j{0,1}a_{i,j}\in\{0,1\}. You are given

bi=j=063ai,j2jb_i=\sum_{j=0}^{63}a_{i,j}2^j

It can be proven that if 0bi<2640\le b_i<2^{64}, then bib_i uniquely corresponds to a set of ai,0,ai,1,,ai,63a_{i,0},a_{i,1},\dots,a_{i,63}.

Input Format

The first line contains a positive integer nn, indicating the length of the postfix notation.

The next line contains nn symbols, representing George's expression.

The next line contains a positive integer mm.

The next line contains mm integers, representing b1,b2,,bmb_1,b_2,\dots,b_m in order.

Output Format

Output mm characters, each being 0 or 1. The ii-th output character represents the value of the expression in the ii-th case.

8
0 1 ^ 2 3 ! & |
7
1 9 1 9 8 1 0
1111010
23
0 ! ! 3 0 3 ^ ^ 3 | & 1 ! ^ 2 0 ! 3 ^ ! ^ ! ^
20
11 10 4 8 13 7 2 5 11 9 16 15 6 9 7 8 15 0 2 10
00110011010101011010

Hint

Explanation for Sample 1

If x=1x=1, then variable 00 is 11, and all other variables are 00.

If x=9x=9, then only variables 00 and 33 are 11.

Constraints

This problem uses bundled testdata.

  • Subtask 1 (7 pts): n,m103n,m\le10^3.
  • Subtask 2 (11 pts): bi[0,281]b_i\in[0,2^{8}-1].
  • Subtask 3 (41 pts): n,m5×104n,m\le5\times10^4.
  • Subtask 4 (41 pts): no additional constraints.

For all testdata, 1n,m1051\le n,m\le10^5, 0bi<2640\le b_i<2^{64}.

Translated by ChatGPT 5