CF1017D.The Wu

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Childan is making up a legendary story and trying to sell his forgery — a necklace with a strong sense of "Wu" to the Kasouras. But Mr. Kasoura is challenging the truth of Childan's story. So he is going to ask a few questions about Childan's so-called "personal treasure" necklace.

This "personal treasure" is a multiset SS of mm "01-strings".

A "01-string" is a string that contains nn characters "0" and "1". For example, if n=4n=4, strings "0110", "0000", and "1110" are "01-strings", but "00110" (there are 55 characters, not 44) and "zero" (unallowed characters) are not.

Note that the multiset SS can contain equal elements.

Frequently, Mr. Kasoura will provide a "01-string" tt and ask Childan how many strings ss are in the multiset SS such that the "Wu" value of the pair (s,t)(s, t) is not greater than kk.

Mrs. Kasoura and Mr. Kasoura think that if si=tis_i = t_i (1≤i≤n1\leq i\leq n) then the "Wu" value of the character pair equals to wiw_i, otherwise 00. The "Wu" value of the "01-string" pair is the sum of the "Wu" values of every character pair. Note that the length of every "01-string" is equal to nn.

For example, if w=[4,5,3,6]w=[4, 5, 3, 6], "Wu" of ("1001", "1100") is 77 because these strings have equal characters only on the first and third positions, so w1+w3=4+3=7w_1+w_3=4+3=7.

You need to help Childan to answer Mr. Kasoura's queries. That is to find the number of strings in the multiset SS such that the "Wu" value of the pair is not greater than kk.

奇尔丹正在编造一个传奇故事,并试图将他的赝品——一条极具“武”气息的项链——卖给卡苏拉一家。但卡苏拉先生却对奇尔丹故事的真实性提出质疑。因此,他打算就奇尔丹所谓的“私人珍宝”项链提出几个问题。

这件“私人珍宝”是一个由 mm 个“01-字符串”构成的多重集 SS。

所谓“01-字符串”,是指长度为 nn、且仅由字符 “0” 和 “1” 组成的字符串。例如,当 n=4n=4 时,“0110”、“0000” 和 “1110” 都是“01-字符串”,而“00110”(长度为 55,非 44)和“zero”(含非法字符)则不是。

注意:多重集 SS 中可以包含相同的元素。

通常,卡苏拉先生会给出一个“01-字符串” tt,并询问奇尔丹:在多重集 SS 中,有多少个字符串 ss 满足:数对 (s,t)(s, t) 的“武”值不超过 kk?

卡苏拉夫人与卡苏拉先生定义:若 si=tis_i = t_i(其中 1≤i≤n1\leq i\leq n),则该位置字符对的“武”值为 wiw_i;否则为 00。整个“01-字符串”数对的“武”值,即为所有位置字符对“武”值之和。注意:每个“01-字符串”的长度均为 nn。

例如,若 w=[4,5,3,6]w=[4, 5, 3, 6],则数对 (“1001”, “1100”) 的“武”值为 77,因为这两个字符串仅在第 11 位和第 33 位的字符相等,故其“武”值为 w1+w3=4+3=7w_1+w_3=4+3=7。

你需要帮助奇尔丹回答卡苏拉先生的查询,即:找出多重集 SS 中满足该数对“武”值不超过 kk 的字符串个数。

输入格式

The first line contains three integers nn, mm, and qq (1≤n≤121\leq n\leq 12, 1≤q,m≤5⋅1051\leq q, m\leq 5\cdot 10^5) — the length of the "01-strings", the size of the multiset SS, and the number of queries.

The second line contains nn integers w1,w2,…,wnw_1, w_2, \ldots, w_n (0≤wi≤1000 \le w_i \le 100) — the value of the ii-th caracter.

Each of the next mm lines contains the "01-string" ss of length nn — the string in the multiset SS.

Each of the next qq lines contains the "01-string" tt of length nn and integer kk (0≤k≤1000\leq k\leq 100) — the query.

第一行包含三个整数 nn、mm 和 qq(1≤n≤121\leq n\leq 12,1≤q,m≤5⋅1051\leq q, m\leq 5\cdot 10^5)——分别表示“01-字符串”的长度、多重集 SS 的大小以及查询次数。

第二行包含 nn 个整数 w1,w2,…,wnw_1, w_2, \ldots, w_n(0≤wi≤1000 \le w_i \le 100)——表示第 ii 个字符的权值。

接下来的 mm 行,每行包含一个长度为 nn 的“01-字符串” ss —— 即多重集 SS 中的一个字符串。

再接下来的 qq 行,每行包含一个长度为 nn 的“01-字符串” tt 和一个整数 kk(0≤k≤1000\leq k\leq 100)—— 表示一次查询。

输出格式

For each query, print the answer for this query.

对于每个查询,输出该查询的答案。

输入输出样例

  • 输入#1

    2 4 5
    40 20
    01
    01
    10
    11
    00 20
    00 40
    11 20
    11 40
    11 60

    输出#1

    2
    4
    2
    3
    4
  • 输入#2

    1 2 4
    100
    0
    1
    0 0
    0 100
    1 0
    1 100

    输出#2

    1
    2
    1
    2

说明/提示

In the first example, we can get:

"Wu" of ("01", "00") is 4040.

"Wu" of ("10", "00") is 2020.

"Wu" of ("11", "00") is 00.

"Wu" of ("01", "11") is 2020.

"Wu" of ("10", "11") is 4040.

"Wu" of ("11", "11") is 6060.

In the first query, pairs ("11", "00") and ("10", "00") satisfy the condition since their "Wu" is not greater than 2020.

In the second query, all strings satisfy the condition.

In the third query, pairs ("01", "11") and ("01", "11") satisfy the condition. Note that since there are two "01" strings in the multiset, the answer is 22, not 11.

In the fourth query, since kk was increased, pair ("10", "11") satisfies the condition too.

In the fifth query, since kk was increased, pair ("11", "11") satisfies the condition too.

在第一个例子中,我们可以得到:

("01", "00") 的 “Wu” 值为 4040。

("10", "00") 的 “Wu” 值为 2020。

("11", "00") 的 “Wu” 值为 00。

("01", "11") 的 “Wu” 值为 2020。

("10", "11") 的 “Wu” 值为 4040。

("11", "11") 的 “Wu” 值为 6060。

在第一个查询中,满足条件的字符串对有 ("11", "00") 和 ("10", "00"),因为它们的 “Wu” 值均不大于 2020。

在第二个查询中,所有字符串对均满足条件。

在第三个查询中,满足条件的字符串对为 ("01", "11") 和 ("01", "11")。注意:由于多重集中存在两个 "01" 字符串,因此答案为 22,而非 11。

在第四个查询中,由于 kk 增大,字符串对 ("10", "11") 也满足条件。

在第五个查询中,由于 kk 进一步增大,字符串对 ("11", "11") 也满足条件。

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

首页