\(\mathcal{Description}\)

  Link.

  有 \(n\) 个小球,坐标为 \(x_{1..n}\);还有 \(m\) 个洞,坐标为 \(y_{1..m}\),保证上述坐标两两不同。每次操作可以将所有小球向左或向右平移一个单位,若有小球的坐标与洞重合则掉进洞内。求所有小球都进洞时有多少种不同的状态。答案对 \((10^9+7)\) 取模。

  \(n,m\le10^5\)。

\(\mathcal{Solution}\)

  ARC 的题嘛……都这副德行。(

  不考虑仅有一个方向有洞的球,可见剩余球要不进入左边最近的洞,要不进入右边最近的洞。设一个距离左边洞 \(x\),右边洞 \(y\) 的小球为 \((x,y)\),那么问题被刻画为:

  平面上有若干点,每次将 \(x\) 轴向上或 \(y\) 轴向右平移一单位。每个点被染色为最先碰到它的坐标轴代表的颜色。求不同染色方案数。

  可证和原问题等价。DP 即可,注意处理转化后重合的坐标。

  复杂度 \(\mathcal O(n\log n)\)。

\(\mathcal{Code}\)

/* Clearink */

#include <cstdio>
#include <algorithm> #define rep( i, l, r ) for ( int i = l, rep##i = r; i <= rep##i; ++i )
#define per( i, r, l ) for ( int i = r, per##i = l; i >= per##i; --i ) inline int rint() {
int x = 0, f = 1, s = getchar();
for ( ; s < '0' || '9' < s; s = getchar() ) f = s == '-' ? -f : f;
for ( ; '0' <= s && s <= '9'; s = getchar() ) x = x * 10 + ( s ^ '0' );
return x * f;
} template<typename Tp>
inline void wint( Tp x ) {
if ( x < 0 ) putchar( '-' ), x = -x;
if ( 9 < x ) wint( x / 10 );
putchar( x % 10 ^ '0' );
} const int MAXN = 1e5, MOD = 1e9 + 7;
int n, m, mx, x[MAXN + 5], y[MAXN + 5], dc[MAXN + 5]; inline int mul( const long long a, const int b ) { return a * b % MOD; }
inline int sub( int a, const int b ) { return ( a -= b ) < 0 ? a + MOD : a; }
inline void subeq( int& a, const int b ) { ( a -= b ) < 0 && ( a += MOD ); }
inline int add( int a, const int b ) { return ( a += b ) < MOD ? a : a - MOD; }
inline void addeq( int& a, const int b ) { ( a += b ) >= MOD && ( a -= MOD ); } struct Point {
int x, y;
inline bool operator < ( const Point& p ) const {
return x != p.x ? x < p.x : y > p.y;
}
} pt[MAXN + 5]; struct BinaryIndexTree {
int val[MAXN + 5]; inline void upd( int x, const int v ) {
for ( ; x <= mx; x += x & -x ) addeq( val[x], v );
} inline int sum( int x ) {
int ret = 0;
for ( ; x; x -= x & -x ) addeq( ret, val[x] );
return ret;
}
} bit; int main() {
// freopen( "hole.in", "r", stdin );
// freopen( "hole.out", "w", stdout ); n = rint(), m = rint();
rep ( i, 1, n ) x[i] = rint();
rep ( i, 1, m ) y[i] = rint(); int cnt = 0;
rep ( i, 1, n ) {
int p = std::lower_bound( y + 1, y + m + 1, x[i] ) - y;
if ( p == 1 || p > m ) continue;
pt[++cnt] = { x[i] - y[p - 1], y[p] - x[i] }, dc[cnt] = pt[cnt].y;
} std::sort( pt + 1, pt + cnt + 1 );
std::sort( dc + 1, dc + cnt + 1 );
mx = std::unique( dc + 1, dc + cnt + 1 ) - dc;
rep ( i, 1, cnt ) {
pt[i].y = std::lower_bound( dc + 1, dc + mx, pt[i].y ) - dc + 1;
} bit.upd( 1, 1 );
rep ( i, 1, cnt ) {
if ( pt[i].x == pt[i - 1].x && pt[i].y == pt[i - 1].y ) continue;
int v = bit.sum( pt[i].y - 1 );
bit.upd( pt[i].y, v );
}
wint( bit.sum( mx ) ), putchar( '\n' );
return 0;
}

Solution -「ARC 101D」「AT4353」Robots and Exits的更多相关文章

  1. Solution Set -「ARC 107」

    「ARC 107A」Simple Math   Link.   答案为: \[\frac{a(a+1)\cdot b(b+1)\cdot c(c+1)}{8} \] 「ARC 107B」Quadrup ...

  2. 「ARC 139F」Many Xor Optimization Problems【线性做法,踩标】

    「ARC 139F」Many Xor Optimization Problems 对于一个长为 \(n\) 的序列 \(a\),我们记 \(f(a)\) 表示从 \(a\) 中选取若干数,可以得到的最 ...

  3. Solution -「CTS 2019」「洛谷 P5404」氪金手游

    \(\mathcal{Description}\)   Link.   有 \(n\) 张卡牌,第 \(i\) 张的权值 \(w_i\in\{1,2,3\}\),且取值为 \(k\) 的概率正比于 \ ...

  4. 【翻译】西川善司「实验做出的游戏图形」「GUILTY GEAR Xrd -SIGN-」中实现的「纯卡通动画的实时3D图形」的秘密,前篇(2)

    Lighting和Shading(2)镜面反射的控制和模拟次级表面散射技术 http://www.4gamer.net/games/216/G021678/20140703095/index_2.ht ...

  5. 「雅礼集训 2018 Day2」农民

    传送门 Description  「搞 OI 不如种田.」 小 D 在家种了一棵二叉树,第 ii 个结点的权值为 \(a_i\). 小 D 为自己种的树买了肥料,每天给树施肥. 可是几天后,小 D 却 ...

  6. 「题解」「美团 CodeM 资格赛」跳格子

    目录 「题解」「美团 CodeM 资格赛」跳格子 题目描述 考场思路 思路分析及正解代码 「题解」「美团 CodeM 资格赛」跳格子 今天真的考自闭了... \(T1\) 花了 \(2h\) 都没有搞 ...

  7. 「Mobile Testing Summit China 2016」 中国移动互联网测试大会-议题征集

    时至北京盛夏,一场由 TesterHome 主办的关于移动互联网测试技术的盛会正在紧锣密鼓的筹备中.只要你关注软件质量,热爱测试,期待学习,都欢迎你加入这次移动测试技术大会中和我们一起分享经验.探讨话 ...

  8. Git 执行 「fork 出来的仓库」和「最新版本的原仓库」内容同步更新

    当我们在 GitHub 上 fork 出一个仓库后,如果原仓库更新了,此时怎样才能保证我们 fork 出来的仓库和原仓库内容一致呢?我们一般关注的是仓库的 master(主干分支)的内容,通过以下步骤 ...

  9. 「Windows MFC 」「Edit Control」 控件

    「Windows MFC 」「Edit Control」 控件

随机推荐

  1. 第10组 Alpha冲刺 (5/6)

    1.1基本情况 ·队名:今晚不睡觉 ·组长博客:https://www.cnblogs.com/cpandbb/p/13996848.html ·作业博客:https://edu.cnblogs.co ...

  2. 新增访客数量MR统计之NewInstallUserMapper中维度信息准备

    关注公众号:分享电脑学习回复"百度云盘" 可以免费获取所有学习文档的代码(不定期更新)云盘目录说明:tools目录是安装包res 目录是每一个课件对应的代码和资源等doc 目录是一 ...

  3. vue3.0+vite+ts项目搭建-postcss-pxtorem 实现移动自适应(五)

    这里不考虑大屏,所以不做amfe-flexible的配置 首先是安装依赖 yarn add postcss-loader postcss-pxtorem -D yarn add autoprefixe ...

  4. 曼孚科技:“四管齐下”筑牢AI数据隐私安全防线

    谈及数据,绕不开的一个话题就是数据隐私与数据安全.随着数字化进程加快,数据安全事件频发,据Risk Based Security统计,去年国际数据泄露事件近5000起,被泄露数据近41亿条,数据造成的 ...

  5. JSON串、JSON对象、Java对象的相互转换

    对象类型转换2: com.alibaba.fastjson.JSONObject时经常会用到它的转换方法,包括Java对象转成JSON串.JSON对象,JSON串转成java对象.JSON对象,JSO ...

  6. 【记录一个问题】铁威马NAS存储中的python3,安装后找不到xml这个包

    如题 因为找不到xml,所以无法安装setuptools 因为无法安装setuptools,所以无法安装pip3 现在准备重新下载python3的源码自己编译. 铁威马的系统中还缺少libm这个库,导 ...

  7. linux中链接错误的时候,快速找到缺失的符号在哪个库中

    编译一个opencv程序,链接的时候出现大量的如下错误: /home/admin/opencv/opencv-master/modules/imgproc/src/color_lab.cpp:23: ...

  8. WebGPU相关的资源学习和社区

    我在网上搜寻了很多关于WebGPU相关的资料: #我觉得首先在B站上看到的徐博士免费教程非常好,讲解详细,并且评论回复比较快,都会有回应,徐博士B站网址:https://space.bilibili. ...

  9. 集合框架-TreeSet集合

    1 package cn.itcast.p5.treeset.demo; 2 3 import java.util.Iterator; 4 import java.util.TreeSet; 5 6 ...

  10. Qt中添加静态库.lb,.a和动态库.dll,.so,头文件和.cpp文件

    添加步骤 1.-Qt Creator中,"项目"------"添加库"2.把静态库和动态库文件放到项目文件夹中3.在.pro文件中会添加如下代码: - 添加动态 ...