BZOJ2741: "Fotile simulation Game" L

Source: Internet
Author: User

2741: "Fotile simulator" L time limit:15 Sec Memory limit:162 MB
submit:1170 solved:303
[Submit] [Status] DescriptionFotile gets a long sequence of N, a, in order to save the Earth, he wants to know the largest contiguous XOR within certain intervals. that is, for a query, you need to ask for Max (Ai xor ai+1 xor ai+2 ... xor Aj), where l<=i<=j<=r. to reflect the online operation, for an inquiry (x, y):L = Min ((( X+lastans) mod n) +1, ((Y+lastans) mod n) +1 ).
r = Max (((X+lastans) mod n) +1, ((Y+lastans) mod n) +1). where Lastans was the answer to the last question, starting at 0. InputThe first line is two integers n and M. The second line has n positive integers, where the number of I is AI and there are extra spaces. The two digits x, y for each line of the rear m row represent a pair of queries.
OutputA total of M lines, and a positive integer on line I indicates the result of the I query. Sample Input3 3
1 4 3
0 1
0 1
4 3


Sample Output5
7
7HINT



HINT

N=12000,m=6000,x,y,ai is within the range of signed Longint.

Source

by Seter

Exercises
Handling: by Seter

Divided into blocks of length L, where the first point of each block is called the key point, there is a total of k=n/l key points.

Processes an array of k*n that represents the answer to each point after each key point. This for a key point is can O (NLGN) out, with the general trie on it, this will not be able to first go to water Usaco again.

Then for a query (U,V), it can be decomposed into (u,v) and (X,v), where X is the first key after U.

Then (X,V) has been processed out, the rest is u ... X the number of O (L) in Max Xor (U,V).

The problem is converted to, for a period of time and X of the difference or maximum.

This thing can be easily chairtrie with the use of a. Chairtrie and Chairtree Almost, is the function of the trie, from high to low processing x one, if you can go in the opposite direction, go, you can ...

Some comments are written in the code.
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 150000+5 -  - #defineMAXM 5000000+5 - #defineMAXK 150 in  - #defineEPS 1e-10 to  + #definell Long Long -  the #definePA pair<int,int> *  $ #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  the #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) +  - #defineMoD 1000000007 $  $ using namespacestd; -  -InlineintRead () the  - {Wuyi  the     intx=0, f=1;CharCh=GetChar (); -  Wu      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} -  About      while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} $  -     returnx*F; -  - } A intn,m,q,tot,rt[maxn],id[maxm],t[maxm][2],A[MAXN],B[MAXK][MAXN]; +InlinevoidInsertintPreintXintk) the { -     intnow=rt[k]=++tot;id[tot]=K; $For3 (I, -,0) the     { the         intJ= (x>>i) &1; thet[now][j^1]=t[pre][j^1];//the null pointer points to the original thet[now][j]=++tot;id[tot]=K; -now=tot; inPre=T[pre][j]; the     } the } AboutInlineintAskintLintRintx) the { the     intans=0, now=Rt[r]; theFor3 (I, -,0) +     { -         intJ= (x>>i) &1)^1; the         if(id[t[now][j]]>=l) ans|=1<<i;Elsej^=1;//The following nodes have IDs that are smaller than L, so change the directionBayinow=T[now][j]; the     } the     returnans; - } -  the intMain () the  the { the  -Freopen ("Input.txt","R", stdin); the  theFreopen ("output.txt","W", stdout); the 94N=read (); q=read (); theFor1 (i,n) a[i]=a[i-1]^read (); theid[0]=-1; theInsert (rt[0],a[0],0);//Insertion 098For1 (i,n) Insert (rt[i-1],a[i],i);//Insert Prefix XOR value About     intLEN=SQRT (n); m=n/len+ (n%len!=0); -For0 (i,m-1)101For2 (j,i*len+1, N)102B[i][j]=max (b[i][j-1],ask (i*len,j-1, A[j]));//Chunking , using a[j] to query the maximum value in I*len-j-1103     intans=0;104      while(q--) the     {106         intx= (LL) read () + (ll) ans)%n+1, y= (LL) read () + (ll) ans)%n+1;107         if(x>y) Swap (x, y); x--;108         intbx=x/len+ (x%len!=0);109Ans=bx*len<y?b[bx][y]:0;//chunks of the answer have been given theFor2 (J,x,min (bx*len,y))111Ans=max (Ans,ask (x,y,a[j));//query Max with point violence within a small block theprintf"%d\n", ans);113     } the  the     return 0; the 117}
View Code

BZOJ2741: "Fotile simulation Game" L

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.