結果

問題 No.1493 隣接xor
コンテスト
ユーザー ryoku
提出日時 2026-08-08 03:47:22
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.90.0)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 203 ms / 2,000 ms
+ 27µs
コード長 38,058 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,596 ms
コンパイル使用メモリ 318,624 KB
実行使用メモリ 31,616 KB
最終ジャッジ日時 2026-08-08 03:47:32
合計ジャッジ時間 8,568 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#line 1 "A/main.cpp"
#line 1 "lib/template.hpp"
#ifdef TEMPLATE
#else
#define TEMPLATE
# pragma GCC optimize("O3")
using namespace std;
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <climits>
#include <cassert>
#include <functional>
#include <iterator>
#include <utility>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <limits>
#include <optional>
#include <variant>
#include <any>

#include <array>
#include <bit>
#include <compare>
#include <concepts>
#include <numbers>
#include <ranges>
#include <span>
#include <string_view>
#include <tuple>
#include <type_traits>
#include <version>
using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using i128=__int128;
using u128=unsigned __int128;
template<class T>using vc=vector<T>;
template<class T>using vvc=vc<vc<T>>;
template<class T>using vvvc=vvc<vc<T>>;
template<class T>using smpq=priority_queue<T,vector<T>,greater<T>>;
template<class T>using bipq=priority_queue<T>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++)
#define DREP(i,n,m) for(ll i=(n);i>=(m);i--)
#define drep(i,n) for(ll i=((n)-1);i>=0;i--)
#define rall(x) x.rbegin(),x.rend()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define is insert
#define bg begin()
#define ed end()
#define all(x) x.begin(),x.end()
void scan(int&a) { cin >> a; }
void scan(ll&a) { cin >> a; }
void scan(string&a) { cin >> a; }
void scan(char&a) { cin >> a; }
void scan(uint&a) { cin >> a; }
void scan(ull&a) { cin >> a; }
void scan(bool&a) { cin >> a; }
void scan(ld&a){ cin>> a;}
template<class T> void scan(vector<T>&a) { for(auto&x:a) scan(x); }
void read() {}
template<class Head, class... Tail> void read(Head&head, Tail&... tail) { scan(head); read(tail...); }
#define INT(...) int __VA_ARGS__; read(__VA_ARGS__);
#define LL(...) ll __VA_ARGS__; read(__VA_ARGS__);
#define ULL(...) ull __VA_ARGS__; read(__VA_ARGS__);
#define STR(...) string __VA_ARGS__; read(__VA_ARGS__);
#define VC(type, name, ...) vector<type> name(__VA_ARGS__); read(name);
#define VVC(type, name, size, ...) vector<vector<type>> name(size, vector<type>(__VA_ARGS__)); read(name);
template<class T>void print(T a) { cout << a; }
template<class T> void print(vector<T>a) { for(int i=0;i<(int)a.size();i++){if(i)cout<<" ";print(a[i]);}cout<<endl;}
void PRT() { cout <<endl; return ; }
template<class T> void PRT(T a) { print(a); cout <<endl; return; }
template<class Head, class... Tail> void PRT(Head head, Tail ... tail) { print(head); cout << " "; PRT(tail...); return; }
template<class T,class F>
bool chmin(T &x, F y){
    if(x>y){
        x=y;
        return true;
    }
    return false;
}
template<class T, class F>
bool chmax(T &x, F y){
    if(x<y){
        x=y;
        return true;
    }
    return false;
}
template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
  return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
  T q = floor(x, y);
  return {q, x - q * y};
}
void YesNo(bool b){
    cout<<(b?"Yes":"No")<<endl;
}
void YESNO(bool b){
    cout<<(b?"YES":"NO")<<endl;
}
void AliceBob(bool b){
    cout<<(b?"Alice":"Bob")<<endl;
}
void TakahashiAoki(bool b){
    cout<<(b?"Takahashi":"Aoki")<<endl;
}
void Yes(){
    cout<<"Yes"<<endl;
}
void No(){
    cout<<"No"<<endl;
}
vc<int>stovi(const string&s,const string&S){
    vc<int>v(s.size());
    rep(i,s.size()){
        auto t=S.find(s[i]);
        assert(t!=string::npos);
        v[i]=t;
    }
    return v;
}
template<class T=ll>
T isqrt(T x){
    T F=sqrtl(x);
    while((F+1)*(F+1)<=x)F++;
    while(F*F>x)F--;
    return F;
}
template<class T>
vvc<T>trans(const vvc<T>&a){
    assert(a.size()&&a[0].size());
    vvc<T>b(a[0].size(),vc<T>(a.size()));
    rep(i,a.size())rep(j,a[0].size()){
        b[j][i]=a[i][j];
    }
    return b;
}
template<class T>
vc<string>trans(const vc<string>&a){
    assert(a.size()&&a[0].size());
    vc<string>b(a[0].size(),string(a.size(),0));
    rep(i,a.size())rep(j,a[0].size()){
        b[j][i]=a[i][j];
    }
    return b;
}
template<class T>
int popcount(T n){
    return __builtin_popcountll(n);
}
template<class T,class L=ll>
L sum(vc<T>&a){
    return accumulate(all(a),L(0));
}
template<class T>
vc<T>subset(T S){
    vc<T>ans;
    for(T x=S;x>0;x=(x-1)&S)ans.pb(x);
    ans.pb(0);
    return ans;
}
template<class T>
T max(vc<T>&a){
    return *max_element(all(a));
}
template<class T>
T min(vc<T>&a){
    return *min_element(all(a));
}
#ifndef COMPRESSER_STRUCT
#define COMPRESSER_STRUCT
template<class T>
struct Compresser{
    vc<T>x;
    Compresser(int n=0){x.reserve(n);}
    Compresser(const vc<T>&xs){
        x=xs;
    }
    void push(T p){built=false;x.pb(p);}
    bool built=false;
    void build(){
        if(!chmax(built,1))return;
        sort(all(x));
        x.erase(unique(all(x)),x.end());
    }
    int find(T v){
        build();
        auto itr=lower_bound(all(x),v)-x.begin();
        if(itr==x.size()||x[itr]!=v)return -1;
        return itr;
    }
    int find_next(T v){
        build();
        return lower_bound(all(x),v)-x.begin();
    }
    int size(){
        build();
        return x.size();
    }
    T operator[](int i)const{
        assert(0<=i&&i<x.size());
        return x[i];
    }
};
#endif
template<class T,class L=ll>
vc<L> presum(vc<T> &a){
    vc<L> ret(a.size()+1);
    rep(i,a.size())ret[i+1]=ret[i]+a[i];
    return ret;
}
template<class T, class F>
vc<T> &operator+=(vc<T> &a,F b){
    for (auto&v:a)v += b;
    return a;
}
template<class T, class F>
vc<T> &operator-=(vc<T>&a,F b){
    for (auto&v:a)v-=b;
    return a;
}
template<class T, class F>
vc<T> &operator*=(vc<T>&a,F b){
    for (auto&v:a)v*=b;
    return a;
}
template<class T=ll>
constexpr T POW(T a,T b){
    T res=1;
    while(b){
        if(b&1)res*=a;
        a*=a;
        b/=2;
    }
    return res;
}
constexpr ll ten(ll a){
    return POW<ll>(10,a);
}
template<typename T>constexpr T inf=numeric_limits<T>::max()/2-1;
template<class T>
int tbit(T x){
    using U=make_unsigned_t<T>;
    U y=(U)x;
    return y?(int)bit_width(y)-1:-1;
}
template<class T>
int lbit(T x){
    using U=make_unsigned_t<T>;
    U y=(U)x;
    return y?(int)countr_zero(y):-1;
}
template<class T>
int tbit(T x,int p){
    using U=make_unsigned_t<T>;
    constexpr int W=numeric_limits<U>::digits;
    U y=(U)x;
    if(p<0)return -1;
    if(p>=W-1)return tbit(y);
    return tbit(y&((U(1)<<(p+1))-1));
}
template<class T>
int lbit(T x,int p){
    using U=make_unsigned_t<T>;
    constexpr int W=numeric_limits<U>::digits;
    U y=(U)x;
    if(p<0)return lbit(y);
    if(p>=W)return -1;
    return lbit(y&(~U(0)<<p));
}
istream& operator>>(istream&is,i128&x){
    string s;is>>s;
    x=0;
    int i=0,neg=0;
    if(s[0]=='-')neg=1,i=1;
    for(;i<(int)s.size();i++)x=x*10+s[i]-'0';
    if(neg)x=-x;
    return is;
}
ostream& operator<<(ostream&os,i128 x){
    if(x==0)return os<<0;
    if(x<0)os<<"-";
    using u128=__uint128_t;
    u128 y=x<0?-(u128)x:(u128)x;
    string s;
    while(y)s.pb('0'+y%10),y/=10;
    reverse(all(s));
    return os<<s;
}
#define dbg(...) 1111

#ifdef LOCAL
#undef dbg

template<class T,class U>
ostream& operator<<(ostream&os,const pair<T,U>&p){
    return os<<"("<<p.fi<<", "<<p.se<<")";
}
template<class T,size_t N>
ostream& operator<<(ostream&os,const array<T,N>&a){
    os<<"[";
    rep(i,N){
        if(i)os<<", ";
        os<<a[i];
    }
    return os<<"]";
}
template<class T>
ostream& operator<<(ostream&os,const vc<T>&a){
    os<<"[";
    rep(i,a.size()){
        if(i)os<<", ";
        os<<a[i];
    }
    return os<<"]";
}
template<class T>
ostream& operator<<(ostream&os,const deque<T>&a){
    os<<"[";
    rep(i,a.size()){
        if(i)os<<", ";
        os<<a[i];
    }
    return os<<"]";
}
template<class T>
ostream& operator<<(ostream&os,const set<T>&s){
    os<<"{";
    bool f=0;
    for(auto&x:s){
        if(f)os<<", ";
        f=1;
        os<<x;
    }
    return os<<"}";
}
template<class T>
ostream& operator<<(ostream&os,const multiset<T>&s){
    os<<"{";
    bool f=0;
    for(auto&x:s){
        if(f)os<<", ";
        f=1;
        os<<x;
    }
    return os<<"}";
}
template<class T>
ostream& operator<<(ostream&os,const unordered_set<T>&s){
    os<<"{";
    bool f=0;
    for(auto&x:s){
        if(f)os<<", ";
        f=1;
        os<<x;
    }
    return os<<"}";
}
template<class T,class U>
ostream& operator<<(ostream&os,const map<T,U>&m){
    os<<"{";
    bool f=0;
    for(auto&x:m){
        if(f)os<<", ";
        f=1;
        os<<x;
    }
    return os<<"}";
}
template<class T,class U>
ostream& operator<<(ostream&os,const unordered_map<T,U>&m){
    os<<"{";
    bool f=0;
    for(auto&x:m){
        if(f)os<<", ";
        f=1;
        os<<x;
    }
    return os<<"}";
}
template<class T>
ostream& operator<<(ostream&os,queue<T>q){
    vc<T>a;
    while(q.size())a.pb(q.front()),q.pop();
    return os<<a;
}
template<class T>
ostream& operator<<(ostream&os,stack<T>s){
    vc<T>a;
    while(s.size())a.pb(s.top()),s.pop();
    return os<<a;
}
template<class T,class C,class F>
ostream& operator<<(ostream&os,priority_queue<T,C,F>q){
    vc<T>a;
    while(q.size())a.pb(q.top()),q.pop();
    return os<<a;
}

void debug_out(){cout<<endl;}
template<class T,class... Ts>
void debug_out(const T&x,const Ts&...xs){
    cout<<x;
    if constexpr(sizeof...(xs))cout<<" ",debug_out(xs...);
    else cout<<endl;
}
#define dbg(...) cout<<"["<<#__VA_ARGS__<<"] = ",debug_out(__VA_ARGS__)
#endif

struct TemplateSetup{
    TemplateSetup(){
        #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        
        #endif
        cin.tie(0)->sync_with_stdio(0);
        #ifdef LOCAL
        cout<<fixed<<setprecision(6);
        dbg("==============="s);
        #else
        cout<<fixed<<setprecision(20);
        #endif
    }
};
inline TemplateSetup template_setup;

#endif
#line 2 "lib/ds/dual-segtree.hpp"
template<class X>
struct DualSegtree{
    using value_type=X::value_type;
    template<class T,class=void>
    struct has_commute{
        static constexpr bool value=false;
    };
    template<class T>
    struct has_commute<T,decltype((void)T::commute,void())>{
        static constexpr bool value=T::commute;
    };
    static constexpr bool commute=has_commute<X>::value;
    vc<value_type>lazy;
    vc<value_type>node;
    int n;
    int lg;
    DualSegtree(int N){
        assert(N>=0);
        lg=0;while((1<<lg)<N)lg++;
        n=1<<lg;
        lazy=vc<value_type>(n,X::e());
        node=vc<value_type>(n*2,X::e());
    }
    DualSegtree(int N,const vc<value_type>&v){
        assert(N>=0);
        lg=0;while((1<<lg)<N)lg++;
        n=1<<lg;
        lazy=vc<value_type>(n,X::e());
        node=vc<value_type>(n*2,X::e());
        build(v);
    }
    void build(const vc<value_type>&v){
        assert((int)v.size()<=n);
        rep(i,n)node[i+n]=v[i];
    }
    void set(int p,value_type x,bool is_first=false){
        assert(0<=p&&p<n);
        if(is_first==0){
            p+=n;
            for(int i=lg;i;i--)push(p>>i);
            node[p]=x;
        }else node[p+n]=x;
    }
    void all_apply(int k,value_type x){
        assert(0<=k&&k<n*2);
        node[k]=X::op(node[k],x);
        if(k<n)lazy[k]=X::op(lazy[k],x);
    }
    void push(int k){
        assert(0<k&&k<n);
        all_apply(k*2,lazy[k]);
        all_apply(k*2+1,lazy[k]);
        lazy[k]=X::e();
    }
    void apply(int l,int r,value_type x){
        assert(0<=l&&l<=r&&r<=n);
        l+=n,r+=n;
        if constexpr(!commute){
            for(int i=lg;i;i--){
                if(((l>>i)<<i)!=l)push(l>>i);
                if(((r>>i)<<i)!=r)push((r-1)>>i);
            }
        }
        while(l<r){
            if(l&1)all_apply(l++,x);
            if(r&1)all_apply(--r,x);
            l/=2,r/=2;
        }
    }
    value_type get(int p){
        assert(0<=p&&p<n);
        p+=n;
        if constexpr(commute){
            value_type res=node[p];
            for(int i=lg;i;i--)res=X::op(res,lazy[p>>i]);
            return res;
        }
        for(int i=lg;i;i--)push(p>>i);
        return node[p];
    }
};
#line 2 "lib/ds/famous.hpp"
template<class T,class=void>
struct FamousHasCommute{
    static constexpr bool value=false;
};
template<class T>
struct FamousHasCommute<T,decltype((void)T::commute,void())>{
    static constexpr bool value=T::commute;
};
template<class Value_type,Value_type inf>
struct Min{
    using value_type=Value_type;
    static constexpr bool commute=true;
    static value_type op(value_type a,value_type b){
        return min(a,b);
    }
    static value_type e(){
        return inf;
    }
    static value_type get(auto a){
        return inf;
    }
};
template<class Value_type,Value_type neg_inf>
struct Max{
    using value_type=Value_type;
    static constexpr bool commute=true;
    static value_type op(value_type a,value_type b){
        return max(a,b);
    }
    static value_type e(){
        return neg_inf;
    }
};
template<class Value_type>
struct Sum{
    using value_type=Value_type;
    static constexpr bool commute=true;
    static value_type op(value_type a,value_type b){
        return a+b;
    }
    static value_type e(){
        return 0;
    }
};
template<class Value_type>
struct Prod{
    using value_type=Value_type;
    static constexpr bool commute=true;
    static value_type op(value_type a,value_type b){
        return a*b;
    }
    static value_type e(){
        return 1;
    }
};
template<class... Infos>
struct Merger{
    using value_type=tuple<typename Infos::value_type...>;
    static constexpr bool commute=(FamousHasCommute<Infos>::value&&...);
    template<size_t... I>
    static value_type op_impl(value_type a,value_type b,index_sequence<I...>){
        return value_type{Infos::op(get<I>(a),get<I>(b))...};
    }
    static value_type op(value_type a,value_type b){
        return op_impl(a,b,index_sequence_for<Infos...>{});
    }
    static value_type e(){
        return value_type{Infos::e()...};
    }
};
template<class Value_type>
struct Affine{
    using value_type=pair<Value_type,Value_type>;
    static value_type op(value_type a,value_type b){
        return {a.first*b.first,a.second*b.first+b.second};
    }
    static value_type e(){
        return {1,0};
    }
};
template<class Value_type>
struct AddMin{
    struct Info{
        using value_type=Value_type;
        static constexpr bool commute=true;
        static value_type op(value_type a,value_type b){
            return min(a,b);
        }
        static value_type e(){
            return numeric_limits<Value_type>::max();
        }
    };
    struct Tag{
        using lazy_type=Value_type;
        static constexpr bool commute=true;
        static lazy_type Merge(lazy_type old_tag,lazy_type new_tag){
            return old_tag+new_tag;
        }
        static lazy_type id(){
            return 0;
        }
        static typename Info::value_type Apply(typename Info::value_type node,lazy_type lz){
            return node+lz;
        }
    };
};
template<class Value_type>
struct AddMax{
    struct Info{
        using value_type=Value_type;
        static constexpr bool commute=true;
        static value_type op(value_type a,value_type b){
            return max(a,b);
        }
        static value_type e(){
            return numeric_limits<Value_type>::lowest();
        }
    };
    struct Tag{
        using lazy_type=Value_type;
        static constexpr bool commute=true;
        static lazy_type Merge(lazy_type old_tag,lazy_type new_tag){
            return old_tag+new_tag;
        }
        static lazy_type id(){
            return 0;
        }
        static typename Info::value_type Apply(typename Info::value_type node,lazy_type lz){
            return node+lz;
        }
    };
};
template<class Value_type>
struct AddSum{
    struct Info{
        using value_type=pair<Value_type,Value_type>;
        static constexpr bool commute=true;
        static value_type op(value_type a,value_type b){
            return {a.first+b.first,a.second+b.second};
        }
        static value_type e(){
            return {0,0};
        }
    };
    struct Tag{
        using lazy_type=Value_type;
        static constexpr bool commute=true;
        static lazy_type Merge(lazy_type old_tag,lazy_type new_tag){
            return old_tag+new_tag;
        }
        static lazy_type id(){
            return 0;
        }
        static typename Info::value_type Apply(typename Info::value_type node,lazy_type lz){
            return {node.first+node.second*lz,node.second};
        }
    };
};
template<class Value_type>
struct AssignMin{
    struct Info{
        using value_type=Value_type;
        static constexpr bool commute=true;
        static value_type op(value_type a,value_type b){
            return min(a,b);
        }
        static value_type e(){
            return numeric_limits<Value_type>::max();
        }
    };
    struct Tag{
        using lazy_type=pair<bool,Value_type>;
        static lazy_type Merge(lazy_type old_tag,lazy_type new_tag){
            if(new_tag.first)return new_tag;
            return old_tag;
        }
        static lazy_type id(){
            return {false,0};
        }
        static typename Info::value_type Apply(typename Info::value_type node,lazy_type lz){
            if(lz.first)return lz.second;
            return node;
        }
    };
};
template<class Value_type>
struct AssignMax{
    struct Info{
        using value_type=Value_type;
        static constexpr bool commute=true;
        static value_type op(value_type a,value_type b){
            return max(a,b);
        }
        static value_type e(){
            return numeric_limits<Value_type>::lowest();
        }
    };
    struct Tag{
        using lazy_type=pair<bool,Value_type>;
        static lazy_type Merge(lazy_type old_tag,lazy_type new_tag){
            if(new_tag.first)return new_tag;
            return old_tag;
        }
        static lazy_type id(){
            return {false,0};
        }
        static typename Info::value_type Apply(typename Info::value_type node,lazy_type lz){
            if(lz.first)return lz.second;
            return node;
        }
    };
};
template<class Value_type>
struct AssignSum{
    struct Info{
        using value_type=pair<Value_type,Value_type>;
        static constexpr bool commute=true;
        static value_type op(value_type a,value_type b){
            return {a.first+b.first,a.second+b.second};
        }
        static value_type e(){
            return {0,0};
        }
    };
    struct Tag{
        using lazy_type=pair<bool,Value_type>;
        static lazy_type Merge(lazy_type old_tag,lazy_type new_tag){
            if(new_tag.first)return new_tag;
            return old_tag;
        }
        static lazy_type id(){
            return {false,0};
        }
        static typename Info::value_type Apply(typename Info::value_type node,lazy_type lz){
            if(lz.first)return {node.second*lz.second,node.second};
            return node;
        }
    };
};
template<class Value_type>
struct AffineSum{
    struct Info{
        using value_type=pair<Value_type,Value_type>;
        static constexpr bool commute=true;
        static value_type op(value_type a,value_type b){
            return {a.first+b.first,a.second+b.second};
        }
        static value_type e(){
            return {0,0};
        }
    };
    struct Tag{
        using lazy_type=pair<Value_type,Value_type>;
        static lazy_type Merge(lazy_type old_tag,lazy_type new_tag){
            return {new_tag.first*old_tag.first,new_tag.first*old_tag.second+new_tag.second};
        }
        static lazy_type id(){
            return {1,0};
        }
        static typename Info::value_type Apply(typename Info::value_type node,lazy_type lz){
            return {node.first*lz.first+node.second*lz.second,node.second};
        }
    };
};
template<class Info>
struct Reversed{
    using value_type=typename Info::value_type;
    static constexpr bool commute=FamousHasCommute<Info>::value;
    static value_type op(value_type a,value_type b){
        return Info::op(b,a);
    }
    static value_type e(){
        return Info::e();
    }
};


template<class Key,class Val,int K,Val neg_inf>
struct MaxK{
    using DATA=MaxK<Key,Val,K,neg_inf>;
    struct T{
        Val val;
        Key key;
        T&operator+=(Val v){val+=v;return *this;}
        T&operator-=(Val v){val-=v;return *this;}
        T operator+(Val v)const{return {val+v,key};}
        T operator-(Val v)const{return {val-v,key};}
        friend T operator+(Val v,const T&a){return a+v;}
    };
    array<T,K> d;
    MaxK(){d.fill({neg_inf,Key{}});}
    T&operator[](int i){return d[i];}
    const T&operator[](int i)const{return d[i];}
    bool has(Key key,Val val)const{
        rep(i,K)if(d[i].val>neg_inf&&d[i].key==key&&d[i].val==val)return true;
        return false;
    }
    int add_element(Key key,Val val){
        if(val<=d[K-1].val)return 0;
        int pos=0;
        while(pos<K&&d[pos].val>=val){
            if(d[pos].key==key)return 0;
            pos++;
        }
        int end=K-1;
        REP(i,pos,K)if(d[i].key==key){end=i;break;}
        DREP(i,end,pos+1)d[i]=d[i-1];
        d[pos]={val,key};
        return 1;
    }
    DATA&merge_data(const DATA&x){
        rep(i,K)add_element(x.d[i].key,x.d[i].val);
        return *this;
    }
    DATA&operator+=(Val v){
        rep(i,K)if(d[i].val>neg_inf)d[i].val+=v;
        return *this;
    }
    DATA&operator-=(Val v){
        rep(i,K)if(d[i].val>neg_inf)d[i].val-=v;
        return *this;
    }
    DATA operator+(Val v)const{return DATA(*this)+=v;}
    DATA operator-(Val v)const{return DATA(*this)-=v;}
    friend DATA operator+(Val v,const DATA&a){return a+v;}
};
template<class Key,class Val,Val neg_inf>
struct MaxK<Key,Val,2,neg_inf>{
    using DATA=MaxK<Key,Val,2,neg_inf>;
    struct T{
        Val val;
        Key key;
        T&operator+=(Val v){val+=v;return *this;}
        T&operator-=(Val v){val-=v;return *this;}
        T operator+(Val v)const{return {val+v,key};}
        T operator-(Val v)const{return {val-v,key};}
        friend T operator+(Val v,const T&a){return a+v;}
    };
    array<T,2> d;
    MaxK(){d.fill({neg_inf,Key{}});}
    T&operator[](int i){return d[i];}
    const T&operator[](int i)const{return d[i];}
    bool has(Key key,Val val)const{
        return (d[0].val>neg_inf&&d[0].key==key&&d[0].val==val)||(d[1].val>neg_inf&&d[1].key==key&&d[1].val==val);
    }
    int add_element(Key key,Val val){
        if(val<=d[1].val)return 0;
        if(key==d[0].key){
            if(val>d[0].val){
                d[0].val=val;
                return 1;
            }
            return 0;
        }
        if(val>d[0].val){
            d[1]=d[0];
            d[0]={val,key};
        }else{
            d[1]={val,key};
        }
        return 1;
    }
    DATA&merge_data(const DATA&x){
        add_element(x.d[0].key,x.d[0].val);
        add_element(x.d[1].key,x.d[1].val);
        return *this;
    }
    DATA&operator+=(Val v){
        if(d[0].val>neg_inf)d[0].val+=v;
        if(d[1].val>neg_inf)d[1].val+=v;
        return *this;
    }
    DATA&operator-=(Val v){
        if(d[0].val>neg_inf)d[0].val-=v;
        if(d[1].val>neg_inf)d[1].val-=v;
        return *this;
    }
    DATA operator+(Val v)const{return DATA(*this)+=v;}
    DATA operator-(Val v)const{return DATA(*this)-=v;}
    friend DATA operator+(Val v,const DATA&a){return a+v;}
};
template<class Key,class Val,int K,Val neg_inf>
struct MaxKInfo{
    using value_type=MaxK<Key,Val,K,neg_inf>;
    static value_type op(const value_type&a,const value_type&b){
        value_type res(a);
        return res.merge_data(b);
    }
    static value_type e(){return value_type();}
};
template<class Key,class Val,int K,Val inf>
struct MinK{
    using DATA=MinK<Key,Val,K,inf>;
    struct T{
        Val val;
        Key key;
        T&operator+=(Val v){val+=v;return *this;}
        T&operator-=(Val v){val-=v;return *this;}
        T operator+(Val v)const{return {val+v,key};}
        T operator-(Val v)const{return {val-v,key};}
        friend T operator+(Val v,const T&a){return a+v;}
    };
    array<T,K> d;
    MinK(){d.fill({inf,Key{}});}
    T&operator[](int i){return d[i];}
    const T&operator[](int i)const{return d[i];}
    bool has(Key key,Val val)const{
        rep(i,K)if(d[i].val<inf&&d[i].key==key&&d[i].val==val)return true;
        return false;
    }
    int add_element(Key key,Val val){
        if(val>=d[K-1].val)return 0;
        int pos=0;
        while(pos<K&&d[pos].val<=val){
            if(d[pos].key==key)return 0;
            pos++;
        }
        int end=K-1;
        REP(i,pos,K)if(d[i].key==key){end=i;break;}
        DREP(i,end,pos+1)d[i]=d[i-1];
        d[pos]={val,key};
        return 1;
    }
    DATA&merge_data(const DATA&x){
        rep(i,K)add_element(x.d[i].key,x.d[i].val);
        return *this;
    }
    DATA&operator+=(Val v){
        rep(i,K)if(d[i].val<inf)d[i].val+=v;
        return *this;
    }
    DATA&operator-=(Val v){
        rep(i,K)if(d[i].val<inf)d[i].val-=v;
        return *this;
    }
    DATA operator+(Val v)const{return DATA(*this)+=v;}
    DATA operator-(Val v)const{return DATA(*this)-=v;}
    friend DATA operator+(Val v,const DATA&a){return a+v;}
};
template<class Key,class Val,Val inf>
struct MinK<Key,Val,2,inf>{
    using DATA=MinK<Key,Val,2,inf>;
    struct T{
        Val val;
        Key key;
        T&operator+=(Val v){val+=v;return *this;}
        T&operator-=(Val v){val-=v;return *this;}
        T operator+(Val v)const{return {val+v,key};}
        T operator-(Val v)const{return {val-v,key};}
        friend T operator+(Val v,const T&a){return a+v;}
    };
    array<T,2> d;
    MinK(){d.fill({inf,Key{}});}
    T&operator[](int i){return d[i];}
    const T&operator[](int i)const{return d[i];}
    bool has(Key key,Val val)const{
        return (d[0].val<inf&&d[0].key==key&&d[0].val==val)||(d[1].val<inf&&d[1].key==key&&d[1].val==val);
    }
    int add_element(Key key,Val val){
        if(val>=d[1].val)return 0;
        if(key==d[0].key){
            if(val<d[0].val){
                d[0].val=val;
                return 1;
            }
            return 0;
        }
        if(val<d[0].val){
            d[1]=d[0];
            d[0]={val,key};
        }else{
            d[1]={val,key};
        }
        return 1;
    }
    DATA&merge_data(const DATA&x){
        add_element(x.d[0].key,x.d[0].val);
        add_element(x.d[1].key,x.d[1].val);
        return *this;
    }
    DATA&operator+=(Val v){
        if(d[0].val<inf)d[0].val+=v;
        if(d[1].val<inf)d[1].val+=v;
        return *this;
    }
    DATA&operator-=(Val v){
        if(d[0].val<inf)d[0].val-=v;
        if(d[1].val<inf)d[1].val-=v;
        return *this;
    }
    DATA operator+(Val v)const{return DATA(*this)+=v;}
    DATA operator-(Val v)const{return DATA(*this)-=v;}
    friend DATA operator+(Val v,const DATA&a){return a+v;}
};
template<class Key,class Val,int K,Val inf>
struct MinKInfo{
    using value_type=MinK<Key,Val,K,inf>;
    static value_type op(const value_type&a,const value_type&b){
        value_type res(a);
        return res.merge_data(b);
    }
    static value_type e(){return value_type();}
};
#line 2 "lib/math/barrett.hpp"
struct Barrett{
    using u64=uint64_t;
    using u32=uint32_t;
    using i128=__int128_t;
    u64 m;
    int mod;
    void set(int mod_){
        assert(mod_>0);
        mod=mod_;
        m=(i128(1)<<64)/mod;
    }
    unsigned reduce(uint64_t x){
        assert(mod>0);
        x-=(((i128)x*m)>>64)*mod;
        return x<mod?x:x-mod;
    }
};
#line 3 "lib/math/dynamic-mod-int.hpp"
template<int id>
struct DynamicModInt{
    using u32=uint32_t;
    using u64=uint64_t;
    u32 val;
    DynamicModInt():val(0){}
    DynamicModInt(ll x){
        ll v=x%get_mod();
        if(v<0)v+=get_mod();
        val=v;
    }
    static DynamicModInt raw(int v){
        assert(v>=0);
        DynamicModInt mi;
        mi.val=v;
        return mi;
    }
    DynamicModInt &operator+=(const DynamicModInt&m){
        if((val+=m.val)>=get_mod())val-=get_mod();
        return *this;
    }
    DynamicModInt &operator-=(const DynamicModInt&m){
        if((val+=(get_mod()-m.val))>=get_mod())val-=get_mod();
        return *this;
    }
    DynamicModInt &operator*=(const DynamicModInt&m){
        val=rem(u64(val)*m.val);
        return *this;
    }
    DynamicModInt &operator/=(const DynamicModInt&m){
        val=rem(u64(val)*m.inv().val);
        return *this;
    }
    DynamicModInt operator-() const{
        return DynamicModInt(val?get_mod()-val:0);
    }
    DynamicModInt operator+() const {
        return *this;
    }
    friend DynamicModInt operator+(DynamicModInt lhs, const DynamicModInt& rhs){
        return lhs+=rhs;
    }
    friend DynamicModInt operator-(DynamicModInt lhs, const DynamicModInt& rhs){
        return lhs-=rhs;
    }
    friend DynamicModInt operator*(DynamicModInt lhs, const DynamicModInt& rhs){
        return lhs*=rhs;
    }
    friend DynamicModInt operator/(DynamicModInt lhs,const DynamicModInt&rhs){
        return lhs/=rhs;
    }
    bool operator==(const DynamicModInt&p) const{
        return p.val==val;
    }
    bool operator!=(const DynamicModInt&p) const{
        return p.val!=val;
    }
    DynamicModInt pow(int64_t n) const{
        DynamicModInt res(1),mul(val);
        while(n){
            if(n%2)res*=mul;
            mul*=mul;
            n/=2;
        }
        return res;
    }

    friend ostream&operator<<(ostream&os,const DynamicModInt&p){
        os<<p.val;
        return os;
    }
    friend istream&operator>>(istream&is,DynamicModInt&p){
        int64_t x;
        is>>x;
        p=DynamicModInt(x);
        return is;
    }
    DynamicModInt inv()const{
        int64_t a=val,b=get_mod(),u=1,v=0,t;
        #ifdef LOCAL
        assert(gcd(a,b)==1);
        #endif
        while(b>0){
            t=a/b;
            swap(a-=t*b,b);
            swap(u-=t*v,v);
        }
        return DynamicModInt(u);
    }
    inline static u32 rem(u64 x){return BarrettReduction().reduce(x);}
    static inline int &get_mod(){
        static int mod=0;
        return mod;
    }
    static void set_mod(int md){
        assert(0<md&&md<=(1ll<<31)-1);
        get_mod()=md;
        BarrettReduction().set(md);
    }
    static inline Barrett&BarrettReduction(){
        static Barrett b;
        return b;
    }
};

#line 3 "lib/math/mod.hpp"
template<class,class=void>
struct BinomHasGetMod:false_type{};
template<class mint>
struct BinomHasGetMod<mint,void_t<decltype(mint::get_mod())>>:true_type{};
template<class mint>
struct Binom{
private:
    static vector<mint>&fact_table(){static vector<mint>v={1};return v;}
    static vector<mint>&invfact_table(){static vector<mint>v={1};return v;}
    static vector<mint>&invs_table(){static vector<mint>v={0};return v;}
    static int&built_mod(){static int mod=-1;return mod;}
public:
    static void build(int n){
        auto&_fact=fact_table();
        auto&_invfact=invfact_table();
        auto&_invs=invs_table();
        if constexpr(BinomHasGetMod<mint>::value){
            auto mod=mint::get_mod();
            if(built_mod()!=mod){
                _fact={1};
                _invfact={1};
                _invs={0};
                built_mod()=mod;
            }
        }
        if(n<(int)_fact.size())return;
        int old=_fact.size();
        _fact.resize(n+1);
        _invfact.resize(n+1);
        _invs.resize(n+1);
        if constexpr(BinomHasGetMod<mint>::value){
            auto mod=mint::get_mod();
            for(int i=old;i<=n;i++){
                _fact[i]=_fact[i-1]*i;
                if(i==1)_invs[i]=1;
                else _invs[i]=-_invs[mod%i]*(mod/i);
                _invfact[i]=_invfact[i-1]*_invs[i];
            }
        }else{
            for(int i=old;i<=n;i++){
                _fact[i]=_fact[i-1]*i;
                _invs[i]=mint(1)/i;
                _invfact[i]=_invfact[i-1]*_invs[i];
            }
        }
    }
    static mint fact(int i){
        assert(i>=0);
        build(i);
        return fact_table()[i];
    }
    static mint invfact(int i){
        assert(i>=0);
        build(i);
        return invfact_table()[i];
    }
    static mint inv(int i){
        assert(i>0);
        build(i);
        return invs_table()[i];
    }
    static mint C(int a,int b){//aCb
        if(a<0||b<0||a-b<0)return mint(0);
        build(a);
        auto&_fact=fact_table();
        auto&_invfact=invfact_table();
        return _fact[a]*_invfact[b]*_invfact[a-b];
    }
    static mint iC(int a,int b){//1/aCb
        if(a<0||b<0||a-b<0)return mint(0);
        build(a);
        auto&_fact=fact_table();
        auto&_invfact=invfact_table();
        return _fact[b]*_fact[a-b]*_invfact[a];
    }
    static mint P(int a,int b){
        if(a<b||b<0)return 0;
        build(a);
        auto&_fact=fact_table();
        auto&_invfact=invfact_table();
        return _fact[a]*_invfact[a-b];
    }
    static mint H(int a,int b){
        return C(a+b-1,b);
    }

};
template< typename T >
T extgcd(T a, T b, T &x, T &y) {
  T d = a;
  if(b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}
template<class T>
pair<T,T> inv(T x,T m){
    T a1,a2;
    T res=extgcd<ll>(x,m,a1,a2);
    T md=m/res;
    a1=(a1%md+md)%md;
    return {a1,md};
}
template<class T>
pair<T,T> mod_solve(T a,T b,T m){//return x s.t. ax=b mod m
    a%=m,b%=m;if(a<0)a+=m;if(b<0)b+=m;
    T g=gcd(gcd(a,b),m);
    a/=g,b/=g,m/=g;
    if(gcd(a,m)>1)return {-1,-1};
    return {(inv<ll>(a,m).first*b)%m,inv<ll>(a,m).second};
}
//https://nyaannyaan.github.io/library/modulo/mod-sqrt.hpp.html
int64_t mod_sqrt(const int64_t &a, const int64_t &p) {
  assert(0 <= a && a < p);
  if (a < 2) return a;
  using Mint = DynamicModInt<409075245>;
  Mint::set_mod(p);
  if (Mint(a).pow((p - 1) >> 1) != 1) return -1;
  Mint b = 1, one = 1;
  while (b.pow((p - 1) >> 1) == 1) b += one;
  int64_t m = p - 1, e = 0;
  while (m % 2 == 0) m >>= 1, e += 1;
  Mint x = Mint(a).pow((m - 1) >> 1);
  Mint y = Mint(a) * x * x;
  x *= a;
  Mint z = Mint(b).pow(m);
  while (y != 1) {
    int64_t j = 0;
    Mint t = y;
    while (t != one) {
      j += 1;
      t *= t;
    }
    z = z.pow(int64_t(1) << (e - j - 1));
    x *= z;
    z *= z;
    y *= z;
    e = j;
  }
  return x.val;
}
#line 3 "lib/math/static-mod-int.hpp"
template<uint32_t mod>
struct StaticModInt{
    static_assert(0<mod&&mod<=(1u<<31)-1);
    using u32=uint32_t;
    using u64=uint64_t;
    u32 val;
    StaticModInt():val(0){}
    StaticModInt(ll x){
        ll v=x%mod;
        if(v<0)v+=mod;
        val=v;
    }
    constexpr static uint32_t get_mod(){
        return mod;
    }
    static StaticModInt raw(int v){
        assert(v>=0);
        StaticModInt mi;
        mi.val=v;
        return mi;
    }
    StaticModInt &operator+=(const StaticModInt&m){
        if((val+=m.val)>=mod)val-=mod;
        return *this;
    }
    StaticModInt &operator-=(const StaticModInt&m){
        if((val+=(mod-m.val))>=mod)val-=mod;
        return *this;
    }
    StaticModInt &operator*=(const StaticModInt&m){
        val=u64(val)*m.val%mod;
        return *this;
    }
    StaticModInt &operator/=(const StaticModInt&m){
        val=u64(val)*m.inv().val%mod;
        return *this;
    }
    StaticModInt operator-() const{
        return StaticModInt(mod-val);
    }
    StaticModInt operator+() const {
        return *this;
    }
    friend StaticModInt operator+(StaticModInt lhs, const StaticModInt& rhs){
        return lhs+=rhs;
    }
    friend StaticModInt operator-(StaticModInt lhs, const StaticModInt& rhs){
        return lhs-=rhs;
    }
    friend StaticModInt operator*(StaticModInt lhs, const StaticModInt& rhs){
        return lhs*=rhs;
    }
    friend StaticModInt operator/(StaticModInt lhs,const StaticModInt&rhs){
        return lhs/=rhs;
    }
    bool operator==(const StaticModInt&p) const{
        return p.val==val;
    }
    bool operator!=(const StaticModInt&p) const{
        return p.val!=val;
    }
    StaticModInt pow(int64_t n) const{
        StaticModInt res(1),mul(val);
        while(n){
            if(n%2)res*=mul;
            mul*=mul;
            n/=2;
        }
        return res;
    }

    friend ostream&operator<<(ostream&os,const StaticModInt&p){
        os<<p.val;
        return os;
    }
    friend istream&operator>>(istream&is,StaticModInt&p){
        int64_t x;
        is>>x;
        p=StaticModInt(x);
        return is;
    }
    StaticModInt inv()const{
        int64_t a=val,b=mod,u=1,v=0,t;
        #ifdef LOCAL
        assert(gcd(a,b)==1);
        #endif
        while(b>0){
            t=a/b;
            swap(a-=t*b,b);
            swap(u-=t*v,v);
        }
        return StaticModInt(u);
    }
};
#line 1052 "A/main.cpp"
using mint=StaticModInt<ten(9)+7>;
void solve(){
    LL(n);
    VC(ll,a,n);
    //n=2e5;a.assign(n,0);
    vc<ll>xs(n);
    map<ll,vc<ll>>is;
    ll now=0;
    rep(i,n){
        xs[i]=(now^=a[i]);
        is[now].pb(i);
    }
    DualSegtree<Sum<mint>>seg(n+1);seg.set(0,1);
    rep(i,n){
        seg.apply(0,n+1,seg.get(i));
        auto itr=lower_bound(all(is[xs[i]]),i);
        if(next(itr)!=is[xs[i]].end()){
            if(*next(itr)+1!=n)seg.set(*next(itr)+1,0);
        }
        //rep(j,n+1)dbg(seg.get(j),j);
    }
    PRT(seg.get(n));
}
signed main(){
    int t=1;
    // cin >> t;
    while(t--)solve();
}
0