HDU3234 & amp; uva12133 & amp; LA4487: Exclusive-OR (Classic with permission and query set)

Source: Internet
Author: User

HDU3234 & uva12133 & LA4487: Exclusive-OR (Classic with permission and query set)
Problem Description You areNotGivenNNon-negative integersX0, 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:


Input There 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.
Output 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 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.

Source 2009 Asia Wuhan Regional Contest Hosted by Wuhan University

Question: For n numbers a [0] ~ A [n-1], but you do not know their values. By gradually providing the information to you, your task is to answer questions based on the information.
I p v: Tell you a [P] = v I P Q V: Tell you a [P] XOR a [Q] = V Q K P1 .. PK: Ask a [P1] ^ a [P2] ^... value of a [PK]
Train of Thought: the classic query set question r [a] records the differences or values between a and his/her father's day points. By checking and merging the set, the r value of a path is updated to fa, fb is a, B, Father's Day respectively. We know that r [a] = a ^ fa, r [B] = B ^ fa, a ^ B = c, then fa is merged, in fb, if fb is the parent node of fa, r [fa] = fa ^ fb and r [a] = a ^ fa, so fa = a ^ r [a] Similarly fb = B ^ r [B] So r [fa] = r [a] ^ r [B] ^ a ^ B = r [a] ^ r [B] ^ c is of course difficult to solve the problem of node merging, in this case, you can add a new node n as the root node so that the value of n is 0. The difference between any value and 0 is itself, and the merge problem is solved.
Then, for queries, we do not need to consider n as the root node, but for those with n as the root node, the value of the root node is calculated repeatedly, at this time, we need to count the number of times the root node is counted. If it is an odd number of times, it must be uncertain.
#include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include
       #include 
        
         #include 
         
          #include 
          
           #include 
           
            #include 
            
             #include #include 
             
              using namespace std;#define lson 2*i#define rson 2*i+1#define LS l,mid,lson#define RS mid+1,r,rson#define UP(i,x,y) for(i=x;i<=y;i++)#define DOWN(i,x,y) for(i=x;i>=y;i--)#define MEM(a,x) memset(a,x,sizeof(a))#define W(a) while(a)#define gcd(a,b) __gcd(a,b)#define LL long long#define N 20005#define INF 0x3f3f3f3f#define EXP 1e-8#define lowbit(x) (x&-x)const int mod = 1e9+7;int n,m,tot;int father[N],r[N],num[N],u,v,w,vis[N];char str[100];int find(int x){ if(x!=father[x]) { int fx = father[x]; father[x] = find(father[x]); r[x]^=r[fx]; } return father[x];}bool Union(int a,int b,int c){ int fa = find(a),fb=find(b); if(fa==fb) { if((r[a]^r[b])!=c) return false; return true; } if(fa==n) swap(fa,fb); father[fa] = fb; r[fa] = r[a]^r[b]^c; return true;}int query(){ int i,j,cnt,ans = 0; MEM(vis,0); for(i = 0; i
              
             
            
           
          
         
        
      
     
    
   
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.