atcoder

luogu

首先可以考虑给一个人\(A\)染色.其他人被染色,要么被本来在后面的速度更快的人染色,要么被在前面的更慢的人染色.然后假设一个速度比最开始那个人慢的人\(B\)最后被染色了,那么最后速度在这两人之间的人都会染色,因为如果这中间的人\(C\)没有直接被最开始那个人染,又因为那个慢的人\(B\)被染色,说明一开始相对位置关系是\(CAB\),因为\(B\)比\(C\)慢,又在\(C\)后面,那么\(B\)被染色后一定会和\(C\)相遇,给\(C\)染色;对于更快的人如果被染色了,那么比他慢比\(A\)快的也会被染色,证明同理.

所以这样看来每个人能染色的人在最后的时刻一定是一段连续区间,具体的说,左端点为速度最慢的并且一开始在\(A\)后面的人,右端点为最快的并且一开始在\(A\)前面的人.然后现在问题变成有\(n\)个区间,问多少种选区间的方案能完全覆盖\([1,n]\).数据结构优化dp即可

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>
#define LL long long
#define db double using namespace std;
const int N=2e5+10,mod=1e9+7;
int rd()
{
int x=0,w=1;char ch=0;
while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
return x*w;
}
struct node
{
int x,y;
bool operator < (const node &bb) const {return y!=bb.y?y<bb.y:x<bb.x;}
}b[N],a[N];
int n,mx[N][20],mi[N][20],l2[N],sm=1;
int gmx(int l,int r)
{
int z=l2[r-l+1];
return max(mx[l][z],mx[r-(1<<z)+1][z]);
}
int gmi(int l,int r)
{
int z=l2[r-l+1];
return min(mi[l][z],mi[r-(1<<z)+1][z]);
}
int c[N];
void ad(int x,int y){while(x<=n) c[x]=(c[x]+y)%mod,x+=x&(-x);}
int gsm(int x){int an=x>=0;while(x>0) an=(an+c[x])%mod,x-=x&(-x);return an;} int main()
{
n=rd();
for(int i=1;i<=n;++i) b[i].x=rd(),b[i].y=rd();
sort(b+1,b+n+1);
for(int i=1;i<=n;++i) mx[i][0]=mi[i][0]=b[i].x;
for(int i=2;i<=n;++i) l2[i]=l2[i>>1]+1;
for(int j=1;j<=l2[n];++j)
for(int i=1;i+(1<<j)-1<=n;++i)
{
mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
mi[i][j]=min(mi[i][j-1],mi[i+(1<<(j-1))][j-1]);
}
for(int i=1;i<=n;++i)
{
a[i].x=a[i].y=i;
int l=1,r=i-1;
while(l<=r)
{
int mid=(l+r)>>1;
if(gmx(1,mid)>b[i].x) a[i].x=mid,r=mid-1;
else l=mid+1;
}
l=i+1,r=n;
while(l<=r)
{
int mid=(l+r)>>1;
if(gmi(mid,r)<b[i].x) a[i].y=mid,l=mid+1;
else r=mid-1;
}
}
sort(a+1,a+n+1);
for(int i=1;i<=n;++i)
{
int ll=a[i].x,rr=a[i].y;
int nf=(sm-gsm(ll-2)+mod)%mod;
sm=(sm+nf)%mod;
ad(rr,nf);
}
printf("%d\n",(sm-gsm(n-1)+mod)%mod);
return 0;
}

AGC015E Mr.Aoki Incubator的更多相关文章

  1. agc015E - Mr.Aoki Incubator(dp)

    题意 题目链接 平面上有$n$个点,每个点都有一个位置$x_i$,和向右的速度$v_i$ 现在要求你对其中的一些点进行染色,当一个点被染色后,在无限距离内与它相遇的点也会被染色 问在可能的$2^n$种 ...

  2. AGC 015 E - Mr.Aoki Incubator

    E - Mr.Aoki Incubator 链接 题意: 数轴上有N个黑点,每个点都有一个方向向右的正速度v.当两个点在同一个位置上重合时,若其中一个是红色,另一个也变成红色.保证没有相同速度或初始坐 ...

  3. 【AGC015E】Mr.Aoki Incubator DP

    题目描述 数轴上有\(n\)个人,每个人的位置是\(x_i\),速度是\(v_i\). 最开始有一些人感染了传染病. 如果某一时刻一个正常人和一个被感染的人处于同一位置,那么这个正常人也会被感染. 问 ...

  4. AtCoder Grand Contest 015 E - Mr.Aoki Incubator

    题目传送门:https://agc015.contest.atcoder.jp/tasks/agc015_e 题目大意: 数轴上有\(N\)个点,每个点初始时在位置\(X_i\),以\(V_i\)的速 ...

  5. 多校联训 DS 专题

    CF1039D You Are Given a Tree 容易发现,当 \(k\) 不断增大时,答案不断减小,且 \(k\) 的答案不超过 \(\lfloor\frac {n}{k}\rfloor\) ...

  6. AtCoder Grand Contest 015

    传送门 A - A+...+B Problem 题意:n个数最大值a,最小值b,求和的可能数量. #include<cstdio> #include<algorithm> us ...

  7. 【AtCoder】AGC015

    AGC015 A - A+...+B Problem #include <bits/stdc++.h> #define fi first #define se second #define ...

  8. 做题记录 To 2019.2.13

    2019-01-18 4543: [POI2014]Hotel加强版:长链剖分+树形dp. 3653: 谈笑风生:dfs序+主席树. POJ 3678 Katu Puzzle:2-sat问题,给n个变 ...

  9. AtCoder Grand Contest 015 题解

    A - A+...+B Problem 常识 Problem Statement Snuke has N integers. Among them, the smallest is A, and th ...

随机推荐

  1. mysql 将时间戳与日期时间的转换

    from_unixtime()是MySQL里的时间函数 mysql>SELECT FROM_UNIXTIME( 1249488000, '%Y%m%d' )  ->20071120 mys ...

  2. Spring boot之使用thymeleaf

    操作步骤 (1)在pom.xml中引入thymeleaf; (2)如何关闭thymeleaf缓存 (3)编写模板文件.html (4)编写访问模板文件controller 在pom.xml中引入thy ...

  3. shiro.ini

    # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreeme ...

  4. springboot的优点

    2013年12月12日,spring发布了4.0版本.这个本来只是作为Java平台上的控制反转容器的库,经过将近10年的发展已经成为了一个巨无霸产品.不过其依靠良好的分层设计,每个功能模块都能保持较好 ...

  5. leetcode241 为运算表达式设计优先级

    class Solution(object): def diffWaysToCompute(self, input): """ :type input: str :rty ...

  6. iOS 图表工具charts之BarChartView

    关于charts的系列视图介绍传送门: iOS 图表工具charts介绍 iOS 图表工具charts之LineChartView iOS 图表工具charts之BarChartView iOS 图表 ...

  7. rocketMQ 订阅关系

    场景:2 个消费者进程中,创建了 2 个消费者,同属于 1 个消费组,但是订阅了不同的 topic,会因为订阅信息相互覆盖,导致拉不到消息. 原因是 rocketMQ 的订阅关系,是根据 group ...

  8. k8s、CI/CD、pipline介绍

    参照文档: https://blog.csdn.net/qq_35299863/article/details/84329798 https://github.com/xgh2016/k8s-CICD ...

  9. Elasticsearch 安装 Head 插件

    引子:在上一篇文章Elasticsearch入门(一):CentOS 7.6 安装ES 7.0.0中,我们讲了如何在CentOS 7.6环境下安装 Elasticsearch 7.0.下面,我将讲一讲 ...

  10. html+css实现奥运五环(环环相扣)

    <!DOCTYPE html> <html> <head> <title>奥运五环</title> <style type=" ...