lINK

不妨认为\(A>B\)。

首先判一下无解。

设\(f_i\)表示\(A\)集合最后选第\(i\)个数的方案数。

转移的话枚举一下从哪个\(j\)转移过来。

显然\(j\)需要满足以下条件:

\(j<i\)

\(S_j<S_i-A\)

\(\forall a,b\in(j,i)\wedge a<b,S_a<S_b-B\)

不难发现\(j\)的取值范围是一个区间,前缀和优化即可。

#include<cstdio>
#include<cctype>
#define ll long long
ll read(){ll x=0;int c=getchar();while(!isdigit(c))c=getchar();while(isdigit(c))x=x*10+c-48,c=getchar();return x;}
const int N=100007,P=1000000007;
int inc(int a,int b){return a+=b,a>=P? a-P:a;}
int dec(int a,int b){return a-=b,a<0? a+P:a;}
int mul(int a,int b){return 1ll*a*b%P;}
ll a[N],f[N],sum[N];
int main()
{
ll n=read(),A=read(),B=read(),i,l,r,ans=0;
if(A<B) A^=B^=A^=B;
for(i=1;i<=n;++i) a[i]=read();
for(i=1;i+2<=n;++i) if(a[i+2]-a[i]<B) return puts("0"),0;
f[0]=sum[0]=1,a[n+1]=B+a[n];
for(i=1,l=r=0;i<=n;++i)
{
while(r<i&&a[i]-a[r+1]>=A) ++r;
if(l<=r) f[i]=inc(f[i],dec(sum[r],l?sum[l-1]:0));
sum[i]=inc(sum[i-1],f[i]);
if(i>1&&a[i]-a[i-1]<B) l=i-1;
}
for(i=n;~i;--i)
{
ans=inc(ans,f[i]);
if(a[i+1]-a[i]<B) break;
}
printf("%d",ans);
}

AT2292 Division into Two的更多相关文章

  1. $AT2292\ Division\ into\ Two$ $dp$

    正解:$dp$ 解题报告: 传送门$QwQ$ 不妨令$A\geq B$,于是先$sort$然后预处理判下如果有三个元素两两差都小于$B$的就直接$GG$了. 然后考虑对集合$X$进行$dp$,剩下的数 ...

  2. 「AT2292」Division into Two

    传送门 Luogu 解题思路 考虑如何 \(\text{DP}\) 为了方便处理,我们设 \(A > B\) 设 \(dp[i]\) 表示处理完 \(1...i\) ,并且第 \(i\) 个数放 ...

  3. python from __future__ import division

    1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...

  4. [LeetCode] Evaluate Division 求除法表达式的值

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

  5. 关于分工的思考 (Thoughts on Division of Labor)

    Did you ever have the feeling that adding people doesn't help in software development? Did you ever ...

  6. POJ 3140 Contestants Division 树形DP

    Contestants Division   Description In the new ACM-ICPC Regional Contest, a special monitoring and su ...

  7. 暴力枚举 UVA 725 Division

    题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...

  8. GDC2016【全境封锁(Tom Clancy's The Division)】对为何对应Eye Tracked System,以及各种优点的演讲报告

    GDC2016[全境封锁(Tom Clancy's The Division)]对为何对应Eye Tracked System,以及各种优点的演讲报告 原文 4Gamer編集部:松本隆一 http:/ ...

  9. Leetcode: Evaluate Division

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

随机推荐

  1. jquery disabled选择器 语法

    jquery disabled选择器 语法 作用:disabled 选择器选取所有禁用的表单元素.大理石平台价格表 语法:$(":disabled") jquery disable ...

  2. 函数返回指针类型(strchr函数)

    #include<stdio.h> #include<string.h> char *mystrchr(char *s,char c) { while(*s) { if(*s ...

  3. Map循环/迭代/遍历效率、性能问题。

    项目开发完毕,为了找点事打发一下时间,于是用findBugs插件对当前完工的项目进行扫描,发现了很多问题.其中有个关于性能的问题,在这里记录一下. 提示信息为:Inefficient use of k ...

  4. mysql 链接数满了的错误 ERROR 1040 (HY000): Too many connections

    mysql 链接数满了的错误 ERROR 1040 (HY000): Too many connections 第一种处理方式: ./mysql -u root -p 登录成功后执行以下语句查询当前的 ...

  5. 微信小程序_(组件)picker

    picker组件效果 官方文档:传送门 Page({ data: { array: ['美国', '中国', '巴西', '日本'], objectArray: [ { id: 0, name: '美 ...

  6. 分布式-信息方式-ActiveMQ的Message dispatch高级特性之(指针) Message cursors

    Message dispatch高级特性之 Message cursors概述            ActiveMQ发送持久消息的典型处现方式是:当消息的消费者准备就绪时,消息发送系统把存储的 消息 ...

  7. 分布式-信息方式-JMS Topic示例

                                                      Topic消息 非持久的 Topic消息示例对于非持久的 Topic消息的发送       基本跟前 ...

  8. python语言中多继承中super调用所有父类的方法以及要用到的MRO顺序

    在python多继承中,利用super().父类方法,可以调用所有父类,从而在重写的状态下,再次对所有父类的调用! 例: print("******多继承使用super().__init__ ...

  9. linux 系统的 cache 过大,解决方案

    linux buff/cache过大,清理脚本 2018年06月20日 13:44:53 taozhe666 阅读数:6500   三条指令: sync echo 1 > /proc/sys/v ...

  10. C++ Map实践

    实践如下: #include <iostream> #include <map> #include <string> #include <typeinfo&g ...