Exclusive-ortime limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2177 accepted submission (s): 603
Problem descriptionyou are
NotGiven
NNon-negative integers
X0, X1,..., Xn-1Less than 220, 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:
Inputthere will be at most 10 test cases. Each case begins with two integers
NAnd
Q(1 <=
N& Lt; = 20,000, 2 & lt; =
Q<= 40,000). Each of the following lines contains either a fact or a question, formatted as stated above.
KParameter in the questions will be a positive integer not greater than 15, and
VParameter in the facts will be a non-negative integer less than 220. The last case is followed
N = q = 0, Which shoshould not be processed.
Outputfor 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 particle question, from the facts I provide you
BeforeThat question, print "I don't know.", without quotes. If
I-Th fact (don't count questions)
CannotBe consistent
AllThe facts before that, print "the first I facts are conflicting. ", then keep silence for everything after that (including facts and questions ). print a blank line after the output of each test case.
Sample Input
2 6I 0 1 3Q 1 0Q 2 1 0I 0 2Q 1 1Q 1 03 3I 0 1 6I 0 2 2Q 2 1 22 4I 0 1 7Q 2 0 1I 0 1 8Q 2 0 10 0
Sample output
Case 1:I don‘t know.312Case 2:4Case 3:7The first 2 facts are conflicting.
Source2009 Asia Wuhan regional contest hosted by Wuhan University
Question:
There are n (n <= 20000) unknown integers x0, X1, X2Xn-1, there are the following Q (q <= 40000) operations:
I P V: Tell you XP = V
I p q V: Tell you XP ^ XQ = V
Q k P1 P2... PK: Ask xp1 XOR xp2 .. XOR xpk, K is not greater than 15.
If the current I conflicts with the previous one
Ideas:
Check the set. Each node record is the same or offset as the root node. If one of the sets knows the value, the set can know the value, (You can mark whether the root has obtained a value, or, as most people on the Internet do, Virtualize a node N with a value of 0 and unify the I operations, if an unknown set has an even number, you can obtain its value U ^ root ^ V ^ root = u ^ V. If it appears an odd number of times, it cannot be obtained. Merge has a small pitfall. See the code.
Code:
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <string> # include <map> # include <stack> # include <vector> # include <set> # include <queue> # include <sstream> # define maxn 20005 # define maxn 100005 # define mod 100000000 # define INF 0x3f3f3f # define PI ACOs (-1.0) # define EPS 1e-8typedef long ll; using namespace STD; int n, m, ANS, CNT, TOT, flag; int pre [maxn], PX [Maxn], Val [maxn], vis [maxn]; vector <int> root, Q [16]; char s [5], buff [100]; int find (int x) {If (x = pre [x]) return X; int r = pre [x]; pre [x] = find (pre [x]); PX [x] = px [R] ^ PX [X]; return pre [X];} bool merge (int u, int V, int W) {int x = find (u), Y = find (V); If (X! = Y) {If (vis [x] | Vis [y]) // If a set knows that the value must be the root of the set that knows the value {If (! Vis [y]) Swap (x, y);} Pre [x] = y; PX [x] = w ^ PX [u] ^ PX [v];} else {If (PX [u] ^ PX [v])! = W) return false;} return true;} void Update () {int U, V, W; CNT ++; gets (buff); stringstream Si; SI. clear (); SI. STR (buff); SI> U; SI> V; If (SI> W) {u ++, V ++; If (FLAG) return; If (! Merge (U, V, W) {flag = 1; printf ("the first % d facts are conflicting. \ n ", CNT) ;}} else {If (FLAG) return; U ++; int r = find (U); If (vis [R]) {If (Val [R]! = (V ^ PX [u]) {flag = 1; printf ("the first % d facts are conflicting. \ n ", CNT) ;}} else {vis [R] = 1; Val [R] = V ^ PX [u] ;}} void query () {int I, j, u, v, k, R, flg; scanf ("% d", & K); root. clear (); for (I = 0; I <K; I ++) Q [I]. clear (); for (I = 1; I <= K; I ++) {scanf ("% d", & U); U ++; int r = find (U); flg = 0; For (j = 0; j <root. size (); j ++) {If (r = root [J]) {flg = 1; Q [J]. push_back (U); break ;}} if (! Flg) {root. push_back (r); Q [root. size ()-1]. push_back (u) ;}} if (FLAG) return; flg = 0; int res = 0; for (I = 0; I <root. size (); I ++) {If (vis [root [I]) {for (j = 0; j <q [I]. size (); j ++) {res ^ = (PX [Q [I] [J] ^ Val [root [I]);} else {If (Q [I]. size () % 2 = 1) {flg = 1; break;} else {for (j = 0; j <q [I]. size (); j + = 2) {u = px [Q [I] [J] ^ PX [Q [I] [J + 1]; res ^ = u ;}}} if (flg) printf ("I don't know. \ n "); else printf (" % d \ n ", res );} Int main () {int I, j, T, U, V, W, test = 0; while (~ Scanf ("% d", & N, & M) {If (n = 0 & M = 0) break; for (I = 1; I <= N; I ++) {pre [I] = I; PX [I] = vis [I] = 0;} flag = CNT = 0; printf ("case % d: \ n", ++ test); for (I = 1; I <= m; I ++) {scanf ("% s ", s); If (s [0] = 'I') Update (); else query ();} puts ("");} return 0 ;}