#include #include using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000001 template struct dynamic_segtree { struct node{ int nxt[2]; S v; node(){ nxt[0] = -1; nxt[1] = -1; v = e(); } }; vector nodes; dynamic_segtree() : dynamic_segtree(0) {} dynamic_segtree(long long n){ log = 0; while((1LL< t(1,0); for(int i=log-1;i>=0;i--){ t.push_back(get_node(t.back(),(p>>i)&1)); } reverse(t.begin(),t.end()); rep(i,t.size()){ if(i==0)nodes[t[i]].v = x; else{ update(t[i]); } } } S get(long long p) { assert(0 <= p && p < _n); int cur = 0; for(int i=log-1;i>=0;i--){ if(!exists(cur,(p>>i)&1))return e(); cur = get_node(cur,(p>>i)&1); } return nodes[cur].v; } S prod(long long l,long long r,int cur,int depth){ if(cur==-1||r-l==0)return e(); if(r-l==(1LL<>(depth-1))&1){ l ^= 1LL<<(depth-1); r ^= 1LL<<(depth-1); return prod(l,r+1,nodes[cur].nxt[1],depth-1); } if(((r>>(depth-1))&1)==0){ return prod(l,r+1,nodes[cur].nxt[0],depth-1); } r ^= 1LL<<(depth-1); return op(prod(l,1LL<<(depth-1),nodes[cur].nxt[0],depth-1),prod(0,r+1,nodes[cur].nxt[1],depth-1)); } S prod(long long l, long long r) { assert(0 <= l && l <= r && r <= _n); return prod(l,r,0,log); } S all_prod() { return nodes[0].v; } void update(int k){ nodes[k].v = e(); rep(i,2){ if(nodes[k].nxt[i]==-1)continue; nodes[k].v = op(nodes[k].v,nodes[nodes[k].nxt[i]].v); } } long long _n,log,size; }; int op(int a,int b){ return a+b; } int e(){ return 0; } int main(){ int last = 0; deque x,y; int N; scanf("%d",&N); int d; rep(i,N){ int A; scanf("%d",&A); A ^= last; x.push_front(0); d = distance(y.begin(),upper_bound(y.begin(),y.end(),A)); y.insert(y.begin()+d,A+1); int ok = A,ng = (1<<30)+1; while(ng-ok>1){ int mid = (ok+ng)/2; if(distance(x.begin(),upper_bound(x.begin(),x.end(),mid))== distance(y.begin(),upper_bound(y.begin(),y.end(),mid)))ng = mid; else ok = mid; } //cout<1){ int mid = (ok+ng)/2; //cout<