QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#11416. 枪打出头鸟

统计

伟大 NIT 很喜欢使用异或来表示世间万物。对于一个由非负整数组成的可重集 $A$(即元素可能有重复的集合),我们称可重集 $A$ 能表示出整数 $x$,当且仅当 $x$ 能写成 $A$ 中若干元素的异或和的形式,即存在一组数 $a_1, a_2, \dots, a_k$($k \ge 0$),其中每个元素 $a_i$ 都属于可重集 $A$,且 $a_1 \oplus a_2 \oplus \cdots \oplus a_k = x$。这里 $\oplus$ 表示异或。

伟大 NIT 很喜欢可重集。伟大 NIT 一共有 $n$ 个可重集,编号依次为 $1$ 到 $n$。他希望每一个可重集都自立自强,能独当一面地表示出世界上每一个非负整数。因此,伟大 NIT 会不断地对这些可重集进行考察。

考察的总次数为 $Q$ 次。每次考察,伟大 NIT 都会给定一个整数 $x$,然后依次检查编号为 $1, 2, 3, \dots$ 的可重集,看看它是否能表示出 $x$。若不能,伟大 NIT 会枪打出头鸟,找到编号最小的那个可重集,予以鞭策。

考察次数多了,伟大 NIT 就倦怠了。于是他找到了你。对于每个考察的数 $x$,他希望你找到最小的 $\mathrm{ans}$,使得所有编号小于 $\mathrm{ans}$ 的可重集都能表示出 $x$,但第 $\mathrm{ans}$ 个可重集却不能表示出 $x$。

特别地,若所有可重集都能表示出 $x$,则 $\mathrm{ans} = n+1$。例如,由定义知任何一个可重集都能表示出 $0$,所以 $x=0$ 时 $\mathrm{ans} = n+1$。

输入格式

第一行两个数 $n,Q$ 分别表示可重集的个数和询问的个数。

接下来 $n$ 行,第 $i$ 行表示第 $i$ 个可重集。每一行第一个数为 $K$,代表可重集里的元素个数。接下来 $K$ 个数表示可重集里的元素。

接下来 $Q$ 行,每行一个数,表示一次考察。

输出格式

$Q$ 行,每行一个 $1\sim n+1$ 的数表示答案。

样例一

input

3 2
4 2744 1021136488 2329479997782303641 935 
4 2 4 935 2329479998801208554 
4 4 51 27 11 
2329479998801208558
2329479997782302782

output

3
2

explanation

对于第一个询问,$2329479998801208558=2744\oplus 1021136488\oplus 2329479997782303641\oplus 935=4\oplus 2329479998801208554$ 但是不能被第三个可重集表示出。

对于第二个询问,$2329479997782302782=2329479997782303641\oplus 935$ 但是不能被第二个可重集表示出。

样例二

input

10 10
10 4260028 34 639922 270 159 204186869390 7872512053053 146273753867518431 7402239233637956033 1286201783702553613 
10 639888 146273648742309091 1 35 4 297 4768557 7872511544459 1431631938076805321 7402244836586944365 
10 1 34 639922 7872507924386 2 4259997 269 146274849013224144 1286207269115909678 8602877971614658540 
10 14 5 1 38 290 4259995 639632 7872507924134 7259140066259904901 1286207269119529986 
10 5 17 297 169 54 4260126 639538 1286201669723691316 7872512053140 8458925429369601838 
10 34 1 2 5 1286201669724199554 300 7872507284533 639924 8458926633202364454 4768258 
10 1 17 316 34 4411 12559 1286201669724199601 647867 7872507928250 8458925429369597578 
10 2 12 7 41 69 255 290 615 7872507284756 639164 
10 34 1 3 270 78 12 2103 21831 12353 780 
10 14 2 578 12320 1 79 28543 89652 45244 368987 
8458926633201955485
8458925530406871954
7259140066259904674
8458926633206084129
7259140066259904573
8602877971614018898
8602877971614018898
8602877971618787311
1286207181167823279
1431631938081065198

output

8
2
7
7
2
4
4
2
2
2

数据范围与提示

子任务编号 $n\leqslant $ $Q\leqslant $ $K_i\leqslant $ 分值
$1$ $10^3$ $10^3$ $64$ $31$
$2$ $10^5$ $10^6$ $20$ $32$
$3$ $64$ $37$

对于所有数据,保证 $\sum K_i\leqslant 10^6,1\leq n\leq 10^5,1\leq Q\leq 10^6,1\leq K_i\leq 64,0\leq a_i,x\lt 2^{64}$。

时间限制:$\texttt{1s}$

空间限制:$\texttt{256MB}$

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.