异或——高级
1 Sec 64 MB | Markdown 显示标签
困难 (*2400) 数据结构 并查集 带权并查集
7 | 112 |
通过 | 提交 |
题目描述
You are **not** given $n$ non-negative integers $X_0, X_1, \dots, X_{n−1}$ less than $2^{20}$, but they do exist, and their values never change.
I'll gradually provide you some facts about them, and ask you some questions.
There are two kinds of facts, plus one kind of question:
| Format | Meaning |
| :------------ | :------------ |
| $\text{I}$ $p$ $v$ | I tell you $X_p = v$ |
| $\text{I}$ $p$ $q$ $v$ | I tell you $X_p \text{ XOR } X_q = v$ |
| $\text{Q}$ $k$ $p_1$ $p_2$ $\dots$ $p_k$ | Please tell me the value of $X_{p_1} \text{ XOR } X_{p_2} \text{ XOR } . . . \text{ XOR } X_{p_k}$ |
---
现在有 $n$ 个非负整数 $X_0, X_1, \dots, X_{n-1}$ 都小于 $2^{20}$,但是你不知道它们的值,并且它们的值是不变的。
现在慢慢的给定一些关于这些数的关系,并且会有一些询问。
一共有两种事实关系和一种询问:
| 格式 | 含义 |
| :------------ | :------------ |
| $\text{I}$ $p$ $v$ | 表示 $X_p = v$ |
| $\text{I}$ $p$ $q$ $v$ | 表示 $X_p \text{ XOR } X_q = v$ |
| $\text{Q}$ $k$ $p_1$ $p_2$ $\dots$ $p_k$ | 要求输出 $X_{p_1} \text{ XOR } X_{p_2} \text{ XOR } . . . \text{ XOR } X_{p_k}$ |
输入格式
Each case begins with two integers $n$ and $Q$ $(1 \le n \le 20, 000, 2 \le Q \le 40, 000)$. Each of the following lines contains either a fact or a question, formatted as stated above. The $k$ parameter in the questions will be a positive integer not greater than $15$, and the $v$ parameter in the facts will be a non-negative integer less than $2^{20}$.
---
第一行包含两个整数 $n$ 和 $Q$ $(1 \le n \le 20, 000, 2 \le Q \le 40, 000)$。
接下来 $Q$ 行,每行包含一个事实关系或者一个询问,格式如题目描述。若是一个询问,其中 $k \le 15$,若是事实关系,则 $0 \le v \lt 2^{20}$。
输出格式
For each test case, print the case number on its own line, then the answers, one on each one. If you can't deduce the answer for a particular question, from the facts I provide you before that question, print `I don't know.`, without quotes. If the $i$-th fact (don't count questions) cannot be consistent with all the facts before that, print `The first i facts are conflicting.`, then keep silence for everything after that (including facts and questions).
---
回答每个询问的问题。如果你无法根据前面提供的事实确定这个答案,则输出 `I don't know.`,不包含引号。如果第 $i$ 个事实(不包含询问)不能与前面的事实相一致,输出 `The first i facts are conflicting.`,并且对下面的事实和询问都不做任何处理。
样例输入 #1
2 6 I 0 1 3 Q 1 0 Q 2 1 0 I 0 2 Q 1 1 Q 1 0
样例输出 #1
I don't know. 3 1 2
样例输入 #2
3 3 I 0 1 6 I 0 2 2 Q 2 1 2
样例输出 #2
4
样例输入 #3
2 4 I 0 1 7 Q 2 0 1 I 0 1 8 Q 2 0 1
样例输出 #3
7 The first 2 facts are conflicting.
来源
UVA 12232