BZOJ3261: Maximum XOR and

Source: Internet
Author: User

3261: Maximum xor and time limit:10 Sec Memory limit:512 MB
submit:543 solved:237
[Submit] [Status] Description     

Given a non-negative integer sequence {A}, the initial length is N.
There are two operation types for m operations:

1, a x: Adds an operation that represents adding a number x to the end of the sequence, n+1 the length of the sequence.
2, Q l R x: Ask the operation, you need to find a position p, meet l<=p<=r, make:

A[P] XOR a[p+1] xor ... xor a[n] xor x maximum, the maximum output is what.

Input

The first line contains two integers N, M, meaning as shown in the problem description.
The second line contains n non-negative integers that represent the initial sequence a.

Next m line, each line describes an operation, the format is described in title face.

Output

Assuming that the ask operation has a T, the output should have a T line, and an integer per line indicates the answer to the question.

Sample Input5 5
2 6 4) 3 6
A 1
Q 3 5 4
A 4
Q 5 7 0
Q 3 6 6
For Test point 1-2,n,m<=5.

For Test point 3-7,n,m<=80000.
For Test point 8-10,n,m<=300000.

Where test points 1, 3, 5, 7, 9 guarantee no modification operation.
For 100% of data, 0<=a[i]<=10^7. Sample Output4
5
6
HINT

For 100% data, 0<=a[i]<=10^7 .

Exercises

Magical and sustainable trie!

The prefix and the X-xor-or-l-1-r-1 trie tree can be queried.

Code:

1#include <cstdio>2 3#include <cstdlib>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten  One#include <iostream> A  -#include <vector> -  the#include <map> -  -#include <Set> -  +#include <queue> -  +#include <string> A  at #defineINF 1000000000 -  - #defineMAXN 1000000+5 -  - #defineMAXM 20000000+5 -  in #defineEPS 1e-10 -  to #definell Long Long +  - #definePA pair<int,int> the  * #defineFor0 (i,n) for (int i=0;i<= (n); i++) $ Panax Notoginseng #defineFor1 (i,n) for (int i=1;i<= (n); i++) -  the #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) +  A #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) the  + #defineMoD 1000000007 -  $ using namespacestd; $  -InlineintRead () -  the { - Wuyi     intx=0, f=1;CharCh=GetChar (); the  -      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} Wu  -      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} About  $     returnx*F; -  - } - intn,m,tot,rt[maxn],id[maxm],t[maxm][2]; AInlinevoidInsertintPreintXintk) + { the     intnow=rt[k]=++tot;id[tot]=K; -For3 (I, -,0) $     { the         intJ= (x>>i) &1; thet[now][j^1]=t[pre][j^1]; thet[now][j]=++tot;id[tot]=k;now=tot; thePre=T[pre][j]; -     } in } theInlineintQueryintLintRintx) the { About     intans=0, now=Rt[r]; theFor3 (I, -,0) the     { the         intJ= (x>>i) &1)^1; +         if(id[t[now][j]]>=l) ans|=1<<i;Elsej^=1; -now=T[now][j]; the     }Bayi     returnans; the } the  - intMain () -  the { the  theFreopen ("Input.txt","R", stdin); the  -Freopen ("output.txt","W", stdout); the  theN=read (); M=read ();intsum=0; theid[0]=-1;94Insert (rt[0],0,0); the For1 (i,n) the     { thesum^=read ();98Insert (rt[i-1],sum,i); About     } -      while(m--)101     {102         CharCh=GetChar ();103          while(ch!='A'&&ch!='Q') ch=GetChar ();104         if(ch=='A') {sum^=read (); Insert (rt[n],sum,n+1); n++;} the         Else106         {107             intL=read (), R=read (), x=read ();108printf"%d\n", Query (l1, R-1, sum^x));109         } the     }111  the     return 0;113  the}
View Code

BZOJ3261: Maximum XOR and

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.