传送门

Luogu

解题思路

考虑如何 \(\text{DP}\)

为了方便处理,我们设 \(A > B\)

设 \(dp[i]\) 表示处理完 \(1...i\) ,并且第 \(i\) 个数放入关于 \(A\) 的集合中的方案。

转移就只需要枚举前一个数 \(j\) 就好了。

但是观察到 \(N \le 10^5\) ,我们就需要考虑优化。

观察到每次 \(j\) 的取值都是一段连续的区间,所以我们可以前缀和优化一下,就可以做到 \(O(n)\)

细节注意事项

  • 咕咕咕

参考代码

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#define rg register
using namespace std;
template < typename T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) s = s * 10 + (c ^ 48), c = getchar();
s = f ? -s : s;
} typedef long long LL;
const int _ = 100010;
const LL p = 1e9 + 7; int n; LL dp[_], sum[_], A, B, a[_]; int main() {
read(n), read(A), read(B); if (A < B) swap(A, B);
for (rg int i = 1; i <= n; ++i) read(a[i]);
for (rg int i = 1; i + 2 <= n; ++i)
if (a[i + 2] - a[i] < B) return puts("0"), 0;
dp[0] = sum[0] = 1;
for (rg int l = 0, r = 0, i = 1; i <= n; ++i) {
while (r < i && a[i] - a[r + 1] >= A) ++r;
if (l <= r) dp[i] = (sum[r] - (l > 0 ? sum[l - 1] : 0ll) + p) % p;
sum[i] = (sum[i - 1] + dp[i]) % p;
if (i > 1 && a[i] - a[i - 1] < B) l = i - 1;
}
LL ans = 0;
for (rg int i = n; ~i; --i) {
ans = (ans + dp[i]) % p;
if (i < n && a[i + 1] - a[i] < B) break;
}
printf("%lld\n", ans);
return 0;
}

完结撒花 \(qwq\)

「AT2292」Division into Two的更多相关文章

  1. 「BZOJ1385」「Baltic2000」Division expression 解题报告

    Division expression Description 除法表达式有如下的形式: \(X_1/X_2/X_3.../X_k\) 其中Xi是正整数且\(X_i \le 1000000000(1 ...

  2. 「译」JUnit 5 系列:条件测试

    原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...

  3. 「译」JUnit 5 系列:扩展模型(Extension Model)

    原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...

  4. JavaScript OOP 之「创建对象」

    工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...

  5. 「C++」理解智能指针

    维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...

  6. 「JavaScript」四种跨域方式详解

    超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...

  7. 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management

    写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...

  8. 「2014-3-18」multi-pattern string match using aho-corasick

    我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...

  9. 「2014-3-17」C pointer again …

    记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...

随机推荐

  1. 基于Modelsim的视频捕获模拟仿真

    一.前言 针对牟新刚编著的<基于FPGA的数字图像处理原理及应用>中第五章系统仿真中关于视频捕获模拟的例子进行补充和仿真验证,简言之,吊书袋子. 2020-02-27 21:09:05 二 ...

  2. Jmeter_用户定义的变量

    1.线程组->添加->配置原件->用户定义的变量 2.自定义变量引用: ${ }

  3. vue修改当前页样式不影响公共样式的方法

    在项目开发中需要对一些标签进行样式修改但是每次修改之后其他页面的样式也会跟着改变, 在网上找了很多方法都不好使后来大神告诉我一种方法很好用分享给大家. 1:首先在template标签下的第一个div中 ...

  4. redis哨兵模式启动redis-sentinel sentinel.conf 报错

    [root@node01 redis-3.2.8]# redis-sentinel sentinel.conf *** FATAL CONFIG FILE ERROR ***Reading the c ...

  5. Nginx笔试题!

    1.Nginx实现HTTP及TCP负载均衡的模块?HTTP就是工作在七层协议TCP工作在四层协议 Nginx七层负载:七层通过虚拟的URL或主机名接收请求在server里面配置location反向代理 ...

  6. 科幻电影免费百度云分享(Scince-fiction cloud share)

    Marvel episode Link  Passcode:6h9k Star War full episode Link Passcode:7abk Men In Black Episode Col ...

  7. vector的使用-Hdu 4841

    圆桌问题 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submis ...

  8. leetCode练题——21. Merge Two Sorted Lists(照搬大神做法)

    1.题目 21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new l ...

  9. leetCode练题——12. Integer to Roman

    1.题目 12. Integer to Roman Roman numerals are represented by seven different symbols: I, V, X, L, C,  ...

  10. linux下的npm安装

    curl --silent --location https://rpm.nodesource.com/setup_10.x | bash - yum install -y nodejs npm in ...