BZOJ3166: [Heoi2013]alo

Source: Internet
Author: User

3166: [Heoi2013]alo time limit:20 Sec Memory limit:256 MB
submit:394 solved:204
[Submit] [Status] Description

Welcome to ALO (arithmetic and Logistic Online). This is a VR MMORPG,
As the name sees, there is a lot of maths puzzles everywhere.
Now that you have n gems, each jewel has an energy density, which is recorded as AI, the energy of these gems
The density is 22 different. Now you can select successive gems (must have more than one) to fuse, set to AI, Ai+1, ..., a J, then the energy density of the fused gems is the secondary value of the energy density of these gems
The energy density of any other gem is a bitwise XOR value, that is, a second large value of the energy density of the gem is set
is k, the energy density of the resulting gem is Max{k XOR ap | ap≠k, I≤p≤j}.
Now you need to know how you choose gems that need to be fused to maximize the energy density of the resulting gem.

Input

The first line, an integer n, represents the number of jewels.
The second line, n integers, represents A1 to an, which represents the energy density of each gem and is guaranteed to have Ai≠aj for i≠j.

Output

Outputs a single integer that represents the maximum energy density of the gem that can be generated.

Sample Input5
9 2 1) 4 7


Sample Output14

HINT



"Sample Interpretation"

Select interval [1,5] with a maximum value of 7 XOR 9.





For 100% of the data is 1≤n≤50000, 0≤ai≤10^9

Source

Enhanced data by Hta

Exercises
Enumeration of this sub-value, then it as the minimum value of the interval is the second to the left of a number larger than its position +1 to the right of the second larger than its position-1, this step can be set (I just started to use the monotone queue ...) )
And then you can persist trie.
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 100000+5 -  - #defineMAXM 2000000+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,mx,l[maxn],r[maxn],a[maxn],tot,sta[maxn],rt[maxn],t[maxm][2],ID[MAXM]; Apair<int,int>B[MAXN]; + Set<int>s; the Set<int>:: iterator it; -InlinevoidInsertintPreintXintk) $ { the     intnow=rt[k]=++tot;id[tot]=K; theFor3 (I, -,0) the     { the         intJ= (x>>i) &1; -t[now][j^1]=t[pre][j^1]; int[now][j]=++tot;id[tot]=K; thenow=tot; thePre=T[pre][j]; About     } the } theInlineintQueryintLintRintx) the { +     intnow=rt[r],ret=0; -For3 (I, -,0) the     {Bayi         intJ= (x>>i) &1)^1; the         if(id[t[now][j]]>=l) ret|=1<<i;Elsej^=1; thenow=T[now][j]; -     } -     returnret; the } theInlineintGetl (intx) the { theit=s.find (x); -     if(It--==s.begin ())return 0; the     if(It--==s.begin ())return 0; the     return*it; the }94InlineintGETR (intx) the { theit=s.find (x); the     if(++it==s.end ())returnn+1;98     if(++it==s.end ())returnn+1; About     return*it; - }101 102 intMain ()103 104 { the 106Freopen ("Input.txt","R", stdin);107 108Freopen ("output.txt","W", stdout);109N=read (); id[0]=-1; theInsert (rt[0],0,0);111 For1 (i,n) the     {113A[i]=read (); Insert (rt[i-1],a[i],i); mx=Max (mx,a[i]); theB[i].first=a[i];b[i].second=i; the     } theSort (b +1, b+n+1);117For3 (I,n,1)118     {119 S.insert (b[i].second); -l[b[i].second]=Getl (b[i].second);121r[b[i].second]=Getr (b[i].second);122     }123     intans=0;124For1 (I,n)if(A[I]!=MX) Ans=max (Ans,query (l[i]+1, r[i]-1, A[i])); theprintf"%d\n", ans);126 127     return 0; - 129}
View Code

BZOJ3166: [Heoi2013]alo

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.