#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef LOCAL # include "debug_print.hpp" # define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define debug(...) (static_cast(0)) #endif using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define rrep(i,n) for(int i=(n)-1; i>=0; i--) #define FOR(i,a,b) for(int i=(a); i<(b); i++) #define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); #define pb push_back using ll = long long; using D = double; using LD = long double; using P = pair; template using PQ = priority_queue>; template using minPQ = priority_queue, greater>; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b ostream &operator<<(ostream &os, const pair &p) { os << p.first << " " << p.second; return os; } template istream &operator>>(istream &is, pair &p) { is >> p.first >> p.second; return is; } template ostream &operator<<(ostream &os, const vector &v) { int s = (int)v.size(); for (int i = 0; i < s; i++) os << (i ? " " : "") << v[i]; return os; } template istream &operator>>(istream &is, vector &v) { for (auto &x : v) is >> x; return is; } void in() {} template void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << sep; out(u...); } void outr() {} template void outr(const T &t, const U &...u) { cout << t; outr(u...); } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; ll left,right; in(n,left,right); if(n == 1){ out(right-left+1); return 0; } vector a(n); in(a); auto get = [&](ll x, int d) -> int{ return (x >> d) & 1; }; vector v(61); stack

seg; seg.push({0,n-1}); rrep(d,61){ stack

nex; int status = 0; while(seg.size()){ auto [l,r] = seg.top(); seg.pop(); int inv_cnt = 0; int inv_idx = -1; FOR(i,l,r){ if(get(a[i], d) != get(a[i+1], d)){ if(inv_cnt == 1){ out(0); return 0; } else{ inv_cnt = 1; inv_idx = i; } } } if(inv_idx == -1){ nex.push({l,r}); } else{ int newr = inv_idx; int newl = inv_idx+1; if(l < newr){ nex.push({l,newr}); } if(newl < r){ nex.push({newl, r}); } if(get(a[inv_idx],d) == 1){ status |= 2; } else{ status |= 1; } } } if((status & 3) == 3){ out(0); return 0; } if(status == 0){ v[d] = -1; } if(status == 1){ v[d] = 0; } if(status == 2){ v[d] = 1; } swap(seg,nex); } if(seg.size()){ out(0); return 0; } auto solve = [&](ll x) -> ll{ if(x < 0) return 0; ll dp[62][2]; rep(i,62)rep(j,2) dp[i][j] = 0; dp[61][0] = 1; rrep(d,61){ if(get(x,d)){ if(v[d] == 1){ dp[d][0] += dp[d+1][0]; dp[d][1] += dp[d+1][1]; } else if(v[d] == 0){ dp[d][1] += dp[d+1][0] + dp[d+1][1]; } else{ dp[d][0] += dp[d+1][0]; dp[d][1] += dp[d+1][0] + dp[d+1][1] * 2; } } else{ if(v[d] == 1){ dp[d][1] += dp[d+1][1]; } else if(v[d] == 0){ dp[d][0] += dp[d+1][0]; dp[d][1] += dp[d+1][1]; } else{ dp[d][0] += dp[d+1][0]; dp[d][1] += dp[d+1][1] * 2; } } } return dp[0][0] + dp[0][1]; }; out(solve(right) - solve(left-1)); }