問題一覧 > 通常問題

No.1245 ANDOR Game (calc)

レベル : / AI推定難易度 : 1200 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 147
作問者 : 👑 tute7627 / テスター : tempura_pp
お気に入りにしたユーザー ProblemId : 4335 / 自分の提出
問題文最終更新日: 2020-10-02 18:41:17
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 268 (順位表) の他の問題:

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).
For a certain operation procedure $S$, you have decided to process the following $Q$ queries.
  • 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$.
Find the answer to each query.

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 0 and 1.
  • 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$ is 1, 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もしくは右上の雲マークをクリックしてアカウントを作成してください。