Uestc_ Qiushi Big Brother and fast food restaurant UESTC Training for Data Structures<problem c>

Source: Internet
Author: User

C-Qiushi Big Brother and fast food restaurant Time limit:3000/1000ms (java/others) Memory limit:65535/65535kb (java/others)SubmitStatus

Toward the Swain, the Twilight Emperor Hall. Qiushi eldest brother in the embrace of lofty ideals, so he opened a fast food restaurant.

Qiushi brother according to the taste of the dish, give each dish a unique CiD, at the same time for the guests to come, according to their taste preferences, Qiushi will give each guest a PI D.

For a label ofPID Of the guest, he was marking for theCID The degree of affection of the dish is Pid∧Cid(∧ denotes bitwise XOR), The larger the value, the more like it.

Qiushi is really busy, and now he needs you to help him look after his shop.

Input

The first line contains an integer n , indicating that Qiushi's restaurant now has n course menu.

The next line contains n integers representing the cI d .

The next line contains an integer m, which indicates that m -things are happening next.

Next m -line, each behavior one of the following two events:

0: said Qiushi eldest brother recently developed a label for  the C of the dish 1: said a mark for p, please find out in the existing dishes a favorite dish of his  

1≤n,m≤100000 , 0≤Pid,Cid≤1000000 .

Output

For each 1 P event output an integer indicating the label of the guest's favorite dish.

Sample Input and output
Sample Input Sample Output
1131 10 21 1
12

Problem Solving Report

First notice that the XOR feature is the same as 0, and the difference is 1. Second, note that the binary number is characterized by the highest advantage, that is, for any one binary number, once its high point is 1, then all the bits since the high point are 1 can not be larger than it.

Therefore, we use a dictionary tree to save each number of binary numbers, from the root near the high, the query when the greedy go method can be used.

#include <iostream>#include<cstring>using namespacestd;/*log2 1e6 is rounded up to 20, that is, the height of the tree is less than or equal to 21 and is stored with a full two fork tree 2^22*/Const intMaxbit = -; typedefstructdata{CharL,r; intID;}; Data tree[(1<< A) + -],n;voidInsertintx) {  intPTR =1, cur =0;  while(Cur <maxbit) {         if(x >> (maxbit-cur-1) &1) {TREE[PTR].R=1; PTR= ptr*2+1; }         Else{TREE[PTR].L=1; PTR<<=1; } cur++; } ptr<<=1; Tree[ptr].id=x;}intFindintx) {   intPTR =1, cur =0, tar = ~x;  while(Cur <maxbit) {       if(Tar >> (maxbit-cur-1)) &1)        {          if(TREE[PTR].R) PTR= ptr*2+1; Elseptr<<=1; }       Else            {           if(TREE[PTR].L) PTR<<=1; Elseptr= ptr*2+1; } cur++; } ptr<<=1; returntree[ptr].id;}intMainintargcChar*argv[]) {  intn,m; memset (Tree,0,sizeof(tree)); scanf ("%d",&N);  for(inti =0; I < n; ++i) {inttemp; scanf ("%d",&temp);   Insert (temp); } scanf ("%d",&m);  while(m--)   {         inti,j; scanf ("%d%d",&i,&j); if(I &1) printf ("%d\n", Find (j)); ElseInsert (j); }  return 0;}

Uestc_ Qiushi Big Brother and fast food restaurant UESTC Training for Data Structures<problem c>

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.