Solution -「ARC 101D」「AT4353」Robots and Exits
\(\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的更多相关文章
- 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 ...
- 「ARC 139F」Many Xor Optimization Problems【线性做法,踩标】
「ARC 139F」Many Xor Optimization Problems 对于一个长为 \(n\) 的序列 \(a\),我们记 \(f(a)\) 表示从 \(a\) 中选取若干数,可以得到的最 ...
- Solution -「CTS 2019」「洛谷 P5404」氪金手游
\(\mathcal{Description}\) Link. 有 \(n\) 张卡牌,第 \(i\) 张的权值 \(w_i\in\{1,2,3\}\),且取值为 \(k\) 的概率正比于 \ ...
- 【翻译】西川善司「实验做出的游戏图形」「GUILTY GEAR Xrd -SIGN-」中实现的「纯卡通动画的实时3D图形」的秘密,前篇(2)
Lighting和Shading(2)镜面反射的控制和模拟次级表面散射技术 http://www.4gamer.net/games/216/G021678/20140703095/index_2.ht ...
- 「雅礼集训 2018 Day2」农民
传送门 Description 「搞 OI 不如种田.」 小 D 在家种了一棵二叉树,第 ii 个结点的权值为 \(a_i\). 小 D 为自己种的树买了肥料,每天给树施肥. 可是几天后,小 D 却 ...
- 「题解」「美团 CodeM 资格赛」跳格子
目录 「题解」「美团 CodeM 资格赛」跳格子 题目描述 考场思路 思路分析及正解代码 「题解」「美团 CodeM 资格赛」跳格子 今天真的考自闭了... \(T1\) 花了 \(2h\) 都没有搞 ...
- 「Mobile Testing Summit China 2016」 中国移动互联网测试大会-议题征集
时至北京盛夏,一场由 TesterHome 主办的关于移动互联网测试技术的盛会正在紧锣密鼓的筹备中.只要你关注软件质量,热爱测试,期待学习,都欢迎你加入这次移动测试技术大会中和我们一起分享经验.探讨话 ...
- Git 执行 「fork 出来的仓库」和「最新版本的原仓库」内容同步更新
当我们在 GitHub 上 fork 出一个仓库后,如果原仓库更新了,此时怎样才能保证我们 fork 出来的仓库和原仓库内容一致呢?我们一般关注的是仓库的 master(主干分支)的内容,通过以下步骤 ...
- 「Windows MFC 」「Edit Control」 控件
「Windows MFC 」「Edit Control」 控件
随机推荐
- react将HTML字符串解析为HTML标签
当后台返回的数据是字符串html的话,我们可以利用dangerouslySetInnerHTML属性来把字符串转换成html标签 function showhtml(htmlString){ var ...
- Spark词频前十的统计练习
注:图片如果损坏,点击文章链接:https://www.toutiao.com/i6815390070254600712/ 承接上一个文档<Spark本地环境实现wordCount单词计数> ...
- Word2010制作日历
原文: https://www.toutiao.com/i6494876164157342222/ 最终效果: 设置页面纸张为"横向". 选择"页面布局"选项卡 ...
- 小程序canvas绘制纯色圆角区域 setdata数组某一项
小程序canvas绘制纯色圆角区域: //方法: roundRectPath:function(ctx, x, y, w, h, r) { ctx.beginPath(); ctx.moveTo(x ...
- spring源码之refresh第二篇
大家好,我是程序员田同学 上篇文章对spring核心启动方法refresh做了整体的解读,但是只是泛泛而谈,接下来会出一系统文章对每个方法的源码进行深刻解读. 第一篇文章见 spring源码之方法概览 ...
- Keil MDK STM32系列(一) 基于标准外设库SPL的STM32F103开发
Keil MDK STM32系列 Keil MDK STM32系列(一) 基于标准外设库SPL的STM32F103开发 Keil MDK STM32系列(二) 基于标准外设库SPL的STM32F401 ...
- java计算器(简单版)
前言 之前在学习完Java的方法后,我发现自己可以开始写计算器这个"经典"的项目了,于是我花了一点时间写下了这个计算器的程序,也写下了这篇文章. 在这里,我需要说明一下,这个程序只 ...
- 个人作业2-Java代码实现数据检索并实现可视化
1.bean实体层 package bean; public class Bean { private String title; private String Abstract; private S ...
- unity3d之sokect通信
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using S ...
- c#重写和多态
多态是基于重写的 继承:向子类中添加父类没有的成员,子类对父类的横向扩展 重写:纵向扩展,成员没有增加,但成员的版本增加了 引言 Rider JetBrains:Rider.ReSharper.dot ...