No.1245 ANDOR Game (calc)
タグ : / 解いたユーザー数 147
作問者 : 👑
tute7627
/ テスター :
tempura_pp
Problem Statement
You have decided to play the following game.
- At the start of the game, you have a non-negative integer $T$, and your score is $0$.
- Using a sequence $A$ of length $N$, repeat the following operation $N$ times.
- In the $i$-th operation, let $X$ be the integer you currently have, and change $X$ to one of the following.
- The bitwise and of $X$ and $A_i$
- The bitwise or of $X$ and $A_i$
- After each operation, the score increases by $|(変化後のX) - (変化前のX)|$ (here, 変化後のX is the integer after the change and 変化前のX is the integer before the change).
- In the $i$-th query, the initial value is $T = t_i$, and you need to find the score after $N$ operations when operating according to the procedure $S$.
Input
$N \ Q$ $A_1 \ A_2 \dots A_N$ $S$ $t_1 \ t_2 \dots t_Q$
- $1 \le N,Q \le 10^5$
- $0 \le A_i \le 10^9$
- $S$ is a string of length $N$ consisting of
0and1. - If the $i$-th character of $S$ is
0, bitwise and is chosen in the $i$-th operation.
If the $i$-th character of $S$ is1, bitwise or is chosen in the $i$-th operation. - $0 \le t_i \le 10^9$
Output
On the $i$-th line, print the answer to the $i$-th query. Print a newline at the end.
Sample
Sample 1
Input
2 2 2 1 01 1 2
Output
2 1
Bitwise and and bitwise or are chosen, in this order.
・When the initial value is $1$
In operation $1$, the integer changes as $1 \to 0$, and the score becomes $1$.
In operation $2$, the integer changes as $0 \to 1$, and the score becomes $2$.
・When the initial value is $2$
In operation $1$, the integer changes as $2 \to 2$, and the score remains $0$.
In operation $2$, the integer changes as $2 \to 3$, and the score becomes $1$.
Sample 2
Input
4 3 0 0 0 0 1111 1 2 3
Output
0 0 0
The result is the same for any initial value.
Sample 3
Input
6 7 8 24 31 25 8 25 010100 18 28 9 5 31 0 21
Output
60 54 35 47 57 42 63
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。