#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 binary variables, numbered from to . He provides the postfix notation of the expression.
The postfix notation may contain the following symbols:
- , representing the corresponding variables.
!&|^, representing the corresponding bitwise operations.
Now Dream has cases. In each case, the values of all 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 be the value of variable in case , where . You are given
It can be proven that if , then uniquely corresponds to a set of .
Input Format
The first line contains a positive integer , indicating the length of the postfix notation.
The next line contains symbols, representing George's expression.
The next line contains a positive integer .
The next line contains integers, representing in order.
Output Format
Output characters, each being 0 or 1. The -th output character represents the value of the expression in the -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 , then variable is , and all other variables are .
If , then only variables and are .
Constraints
This problem uses bundled testdata.
- Subtask 1 (7 pts): .
- Subtask 2 (11 pts): .
- Subtask 3 (41 pts): .
- Subtask 4 (41 pts): no additional constraints.
For all testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号