CF1033F.Boolean Computer

省选/NOI-

通过率:0%

时间限制:7.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice has a computer that operates on ww-bit integers. The computer has nn registers for values. The current content of the registers is given as an array a1,a2,…,ana_1, a_2, \ldots, a_n.

The computer uses so-called "number gates" to manipulate this data. Each "number gate" takes two registers as inputs and calculates a function of the two values stored in those registers. Note that you can use the same register as both inputs.

Each "number gate" is assembled from bit gates. There are six types of bit gates: AND, OR, XOR, NOT AND, NOT OR, and NOT XOR, denoted "A", "O", "X", "a", "o", "x", respectively. Each bit gate takes two bits as input. Its output given the input bits b1b_1, b2b_2 is given below:

b1b2AOXaox00000111010111001001110011110001\begin{matrix} b_1 & b_2 & A & O & X & a & o & x \\ 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 \\ 0 & 1 & 0 & 1 & 1 & 1 & 0 & 0 \\ 1 & 0 & 0 & 1 & 1 & 1 & 0 & 0 \\ 1 & 1 & 1 & 1 & 0 & 0 & 0 & 1 \\ \end{matrix}

To build a "number gate", one takes ww bit gates and assembles them into an array. A "number gate" takes two ww-bit integers x1x_1 and x2x_2 as input. The "number gate" splits the integers into ww bits and feeds the ii-th bit of each input to the ii-th bit gate. After that, it assembles the resulting bits again to form an output word.

For instance, for 44-bit computer we might have a "number gate" "AXoA" (AND, XOR, NOT OR, AND). For two inputs, 13=1101213 = 1101_2 and 10=1010210 = 1010_2, this returns 12=1100212 = 1100_2, as 11 and 11 is 11, 11 xor 00 is 11, not (00 or 11) is 00, and finally 11 and 00 is 00.

You are given a description of mm "number gates". For each gate, your goal is to report the number of register pairs for which the "number gate" outputs the number 00. In other words, find the number of ordered pairs (i,j)(i,j) where 1≤i,j≤n1 \leq i,j \leq n, such that wk(ai,aj)=0w_k(a_i, a_j) = 0, where wkw_k is the function computed by the kk-th "number gate".

Alice 有一台运行在 ww 位整数上的计算机。该计算机有 nn 个寄存器用于存储数值。当前各寄存器的内容由数组 a1,a2,…,ana_1, a_2, \ldots, a_n 给出。

该计算机使用所谓的“数值门”(number gates)来操作这些数据。每个“数值门”接收两个寄存器作为输入,并计算这两个寄存器中所存数值的某个函数。注意:同一个寄存器可同时作为两个输入。

每个“数值门”由若干“位门”(bit gates)组装而成。共有六种类型的位门:AND(与)、OR(或)、XOR(异或)、NOT AND(与非)、NOT OR(或非)、NOT XOR(异或非),分别用字符 "A"、"O"、"X"、"a"、"o"、"x" 表示。每种位门接收两个比特作为输入,其输出如下表所示(其中 b1b_1、b2b_2 为输入比特):

b1b2AOXaox00000111010111001001110011110001\begin{matrix} b_1 & b_2 & A & O & X & a & o & x \\ 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 \\ 0 & 1 & 0 & 1 & 1 & 1 & 0 & 0 \\ 1 & 0 & 0 & 1 & 1 & 1 & 0 & 0 \\ 1 & 1 & 1 & 1 & 0 & 0 & 0 & 1 \\ \end{matrix}

要构造一个“数值门”,需取 ww 个位门并将其排成一维阵列。一个“数值门”接收两个 ww 位整数 x1x_1 和 x2x_2 作为输入。该门将两个整数各自拆分为 ww 个比特,并将每个输入的第 ii 个比特送入第 ii 个位门。随后,将所有位门的输出比特重新组合成一个 ww 位输出字。

例如,在一台 4 位计算机上,可能存在一个“数值门”"AXoA"(即:AND、XOR、NOT OR、AND)。对两个输入 13=1101213 = 1101_2 和 10=1010210 = 1010_2,其输出为 12=1100212 = 1100_2,因为:11 AND 1=11 = 1,11 XOR 0=10 = 1,NOT (00 OR 11) = NOT 1=01 = 0,最后 11 AND 0=00 = 0。

现给出 mm 个“数值门”的描述。对每个门,你的任务是报告有多少对寄存器使得该“数值门”的输出为 00。换言之,求满足 wk(ai,aj)=0w_k(a_i, a_j) = 0 的有序对 (i,j)(i,j) 的数量,其中 1≤i,j≤n1 \leq i,j \leq n,且 wkw_k 表示第 kk 个“数值门”所计算的函数。

输入格式

The first line contains three integers: ww, nn, and m (1≤w≤12,1≤n≤3⋅104,1≤m≤5⋅104)m~(1 \leq w \leq 12, 1 \leq n \leq 3\cdot 10^4, 1 \leq m \leq 5\cdot 10^4) — the word size, the number of variables, and the number of gates.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai<2w)(0 \leq a_i \lt 2^w) — the value of variables stored in the registers.

Each of the next mm lines contains a string gj (∣gj∣=w)g_j~(|g_j| = w) with a description of a single gate. Each character of gjg_j is one of "A", "O", "X", "a", "o", "x".

第一行包含三个整数:ww、nn 和 mm(1≤w≤121 \leq w \leq 12,1≤n≤3⋅1041 \leq n \leq 3\cdot 10^4,1≤m≤5⋅1041 \leq m \leq 5\cdot 10^4)—— 分别表示字长、变量个数和门电路个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai<2w0 \leq a_i \lt 2^w)—— 表示存储在寄存器中的各变量的值。

接下来的 mm 行中,每行包含一个长度为 ww 的字符串 gjg_j,用于描述一个门电路。gjg_j 的每个字符均为以下之一:"A"、"O"、"X"、"a"、"o"、"x"。

输出格式

Print mm lines. The ii-th line should contain the number of ordered pairs of variables for which the ii-th gate returns zero.

输出 mm 行。第 ii 行应包含使得第 ii 个逻辑门输出为零的变量有序对的数量。

输入输出样例

  • 输入#1

    4 3 1
    13 10 6
    AXoA

    输出#1

    3
  • 输入#2

    1 7 6
    0 1 1 0 1 0 0
    A
    O
    X
    a
    o
    x

    输出#2

    40
    16
    25
    9
    33
    24
  • 输入#3

    6 2 4
    47 12
    AOXaox
    AAaaAA
    xxxxxx
    XXXXXX

    输出#3

    2
    3
    0
    2
  • 输入#4

    2 2 2
    2 0
    xO
    Ox

    输出#4

    2
    0

说明/提示

In the first test case, the inputs in binary are 11011101, 10101010, 01100110. The pairs that return 00 are (13,6)(13, 6), (6,13)(6, 13), and (6,6)(6, 6). As it was already mentioned in the problem statement, 13⊕10=10⊕13=1213 \oplus 10 = 10 \oplus 13 = 12. The other pairs are 13⊕13=1113 \oplus 13 = 11, 10⊕10=810 \oplus 10 = 8 and 10⊕6=6⊕10=410 \oplus 6 = 6 \oplus 10 = 4.

在第一个测试用例中,输入的二进制表示分别为 11011101、10101010、01100110。结果为 00 的数对是 (13,6)(13, 6)、(6,13)(6, 13) 和 (6,6)(6, 6)。如题目描述中已指出,13⊕10=10⊕13=1213 \oplus 10 = 10 \oplus 13 = 12。其余数对的结果为:13⊕13=1113 \oplus 13 = 11、10⊕10=810 \oplus 10 = 8,以及 10⊕6=6⊕10=410 \oplus 6 = 6 \oplus 10 = 4。

输入解题思路,AI测评打分。不知道怎么写?

首页