正解:$dp$
解题报告:
不妨令$Ageq B$,于是先$sort$然后预处理判下如果有三个元素两两差都小于$B$的就直接$GG$了.
然后考虑对集合$X$进行$dp$,剩下的数放到$Y$就成.设$f_i$表示集合$X$最后一个选择的是$i$时的方案数,就有$f_i=sum f_j,a_i-a_jgeq A$.
嗷然后因为我很呆所以我开始想的时候漏了个条件把代码打完才发现样例都过不去,,,就还需要$[j+1,i-1]$中任意两个数的差大于等于$B$.显然$j$就一段区间,前缀和优化一波就完事$QwQ$
#include<bits/stdc++.h> using namespace std; #define il inline #define int long long #define gc getchar() #define t(i) edge[i].to #define w(i) edge[i].wei #define ri register int #define rc register char #define rb register bool #define rp(i,x,y) for(ri i=x;i<=y;++i) #define my(i,x,y) for(ri i=x;i>=y;--i) const int N=1e5+10,mod=1e9+7; int n,a[N],A,B,f[N],sum[N],pos1,pos2,as; il int read() { rc ch=gc;ri x=0;rb y=1; while(ch!='-' && (ch>'9' || ch<'0'))ch=gc; if(ch=='-')ch=gc,y=0; while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc; return y?x:-x; } il int dec(ri x,ri y){x-=y;if(x<0)x+=mod;return x;} il int ad(ri x,ri y){x+=y;if(x>=mod)x-=mod;return x;} signed main() { //freopen("2292.in","r",stdin);freopen("2292.out","w",stdout); n=read();A=read();B=read();rp(i,1,n)a[i]=read();sort(a+1,a+1+n);if(A<B)swap(A,B); rp(i,3,n)if(a[i]-a[i-2]<B)return printf("0 "),0;;f[0]=sum[0]=1; rp(i,1,n) { while(a[i]-a[pos1+1]>=A)++pos1;;if(pos2<=pos1)f[i]=dec(sum[pos1],pos2?sum[pos2-1]:0); sum[i]=ad(sum[i-1],f[i]);if(a[i]-a[i-1]<B && i>1)pos2=i-1; } my(i,n,0){as=ad(as,f[i]);if(i<n && a[i+1]-a[i]<B)break;}printf("%lld ", as); return 0; }