1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| #include<bits/stdc++.h> #define inf 0x3f3f3f3f3f3f3f3fll #define debug(x) cerr<<#x<<"="<<x<<endl using namespace std; const int mod=1000000007; using ll=long long; using ld=long double; using pli=pair<ll,int>; using pi=pair<int,int>; template<typename A> using vc=vector<A>; inline int read() { int s=0,w=1;char ch; while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1; while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } inline ll lread() { ll s=0,w=1;char ch; while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1; while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } ll num[25000001]; int ls[25000001]; int rs[25000001]; ll a[200001]; int r1,r2; ll k1,k2; int cnt; ll mi=inf; int n; ll get(int p,int dep,ll v,ll lim) { if(!p) return 0; if(dep==-1) return num[p]; if((lim>>dep)&1) { if((v>>dep)&1) return get(ls[p],dep-1,v,lim); return get(rs[p],dep-1,v,lim); } else { if((v>>dep)&1) return num[ls[p]]+get(rs[p],dep-1,v,lim); return num[rs[p]]+get(ls[p],dep-1,v,lim); } } void ins(int &p,int dep,ll x,ll y) { if(!p) p=++cnt; num[p]+=y;if(num[p]>=mod) num[p]-=mod; if(dep==-1) return ; if((x>>dep)&1) ins(rs[p],dep-1,x,y); else ins(ls[p],dep-1,x,y); } int main() { n=read(),k1=lread(),k2=lread(); for(int i=1;i<=n;i++) a[i]=lread(); sort(a+1,a+n+1,[](ll a,ll b){ return a<b;}); for(int i=1;i<=n;i++) { ll v1=get(r1,59,a[i],k2)%mod; ll v2=get(r2,59,a[i],k1)%mod; if((a[i-1]^a[i])<k1) r1=0; if((a[i-1]^a[i])<k2) r2=0; if(i>=2) { ins(r2,59,a[i-1],v1+(mi>=k1)); ins(r1,59,a[i-1],v2+(mi>=k2)); mi=min(mi,a[i-1]^a[i]); } } printf("%lld\n",(num[r1]+num[r2])%mod); return 0; }
|