题解 【AT4353 [ARC101D] Robots and Exits】
DreamsChaser · · 题解
更好的阅读体验:https://www.cnblogs.com/DreamsChaser/p/15272849.html
在一个数轴上有
每次操作可以把所有
求
答案对
首先我们可以不管比最左边
我们现在单独拎出一个
其实所有
那一个
而且答案只取决于曲线先碰到
如果将
对于每个从右侧
感性理解一下,就是卡在每个
那么方案数就等于这样的直线的个数。令
然后这是一个
const int N = 100010, mod = 1000000007;
int n, m, a[N], b[N], Max, dc[N];
pair<int, int> node[N];
struct BIT // 树状数组
{
int c[N];
void add(reg int x, reg int d) {for (; x <= Max; x += (x & (-x))) c[x] = (c[x] + d) % mod;}
int ask(reg int x) {reg int sum = 0; for (; x; x -= (x & (-x))) sum = (sum + c[x]) % mod; return sum;}
} S;
int main()
{
scanf("%d %d", &n, &m);
for (reg int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
for (reg int i = 1; i <= m; ++ i) scanf("%d", &b[i]);
reg int tot = 0;
for (reg int i = 1; i <= n; ++ i)
{
reg int pos = lower_bound(b + 1, b + m + 1, a[i]) - b;
if (pos == 1 || pos > m) continue;
node[ ++ tot] = make_pair(a[i] - b[pos - 1], - (b[pos] - a[i]));
dc[tot] = -node[tot].second;
}
// 离散化
sort(node + 1, node + tot + 1);
for (reg int i = 1; i <= n; ++ i) node[i].second *= -1;
sort(dc + 1, dc + tot + 1);
Max = unique(dc + 1, dc + tot + 1) - dc;
for (reg int i = 1; i <= tot; ++ i) node[i].second = lower_bound(dc + 1, dc + Max, node[i].second) - dc + 1;
// DP
S.add(1, 1);
for (reg int i = 1; i <= tot; ++ i)
{
if (node[i].first == node[i - 1].first && node[i].second == node[i - 1].second) continue;
reg int t = S.ask(node[i].second - 1);
S.add(node[i].second, t);
}
printf("%d\n", S.ask(Max));
return 0;
}