B. Buses Codeforces Beta Round 79 (Div. 1 Only)

40 篇文章 0 订阅
14 篇文章 0 订阅

传送门

 

题意:

给定一个数n,起点是0  终点是n,有m两车,每辆车是从s开去t的,我们只能从[s,s+1,s+2....t-1]处上车,从t处下车。问能否去到点n,并且求方案数

设L[x]表示有多少辆车能够到达x处。

只能从t处下车:说明只能单点更新,对于没辆车x,在区间[s,s+1,s+2....t-1]内上车是可以得,那么有多少辆车呢?明显就是∑区间里能到达的点。然后单点更新t即可

数据大,明显不能到达的点是没用的,离散化一下即可。

坑点:因为车是无序的,所以应该优先处理最快下车的点。这样就能对后面进行更新

 用树状数组来解决。

AC代码:

//
//                                                    ................                                                .................,`..,`.................
//                                                    .....=^..=^..=^.                                                .=^..=^..=^..=^..=^..=^..=^...*.........
//                                            ...*,/\`,/\^,\..,\..,\..,/\`,/\`,/\`...*...*                        ...*,\..,\..,\..,\..,\..,\..,\..=^=^,`,`,`,`
//                                            .,].=^..=^=^,`=^,`=^,`=^=^..=^..=^...,]..,].                        .,].,`=^,`=^,`=^,`=^,`=^,`=^,`=^=^*.........
//                                    .....................,`..,`..,`.....................................        .....,`..,`..,`..,`..,`..,`..,`.
//                                    .=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^.        .=^..=^..=^..=^..=^..=^.........
//                                ,[\^,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,/\`,/\`,\..,\..,\..,\..,\..,\..,`,`
//                                ,/*.,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^=^..=^..,`=^,`=^,`=^,`=^,`=^,`=^....
//                        .............,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..........,`..,`..,`..,`..,`..,`.
//                        .....=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^.........
//                    ...*,/\^,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,`,`
//                    .,].=^=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^....
//                .............,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`.........
//                .=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^.
//            ...*,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,/\`...*...*
//            .,].,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^=^...,]..,].
//        .........,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`.....................................
//        .=^..=^..............................................=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^.....
//    ...*,\..,\...\/`.\/`.\/`.\/`,`,`,`,`,`,`,`,`.\/`.\/`.\/`,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..=/\`,/\`...*
//    .,].,`=^,`=^.[,`.[,`.[,`.[,`.................[,`.[,`.[,`,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^=^=^=^...,].
//        .,`..,`.                                            .,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`.................
//        ........                                            .............................=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^.....
//                                                                        ,`,`,`,`.\/`.\/`,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..=^..
//                                                                        .........[,`.[,`,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^=^..
//                                                                                    .....,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`.....
//                                                                                    .=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^.
//                                                                                ,[\^,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..
//                                                                                ,/*.,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^
//                                                                            .........,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`.
//                                                                            .=^..=^..=^..=^..=^..=^..=^..=^.. ...........=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^..=^.
//                                                                        ...*,\..,\..,\..,\..,\..,\..,\..,\..=^=^.\/`.\/`,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..
//                                                                        .,].,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^=^*..[,`.[,`,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^
//                                                                    .........,`..,`..,`..,`..,`..,`..,`..,`.            .,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`..,`.
//                                                                    .....=^..=^..=^..=^..=^..=^..=^.........            .............................................=^..=^..=^..=^..=^.
//                                                                    ,/\^,\..,\..,\..,\..,\..,\..,\..,`,`                                                        .@=^,\..,\..,\..,\..,\..
//                                                                    =^=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^....                                                        ,[\/,`=^,`=^,`=^,`=^,`=^
//                                                                .........,`..,`..,`..,`..,`..,`..,`.                                                                .,`..,`..,`..,`..,`.
//                                                                .=^..=^..=^..=^..=^..=^..=^..=^..=^.                                                                .=^..=^..=^.. ......
//                                                            ,[\^,\..,\..,\..,\..,\..,\..,\..,\..,\..                                                                ,\..,\..,\..=^=^,`,`
//                                                            ,/*.,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^                                                                ,`=^,`=^,`=^=^*.....
//                                                        .........,`..,`..,`..,`..,`..,`..,`..,`..,`*                                                                .,`..,`..,`.
//                                                        .....=^..=^..=^..=^..=^..=^..=^..=^..=^....*                                                                .=^.. ......
//                                                        ,/\^,\..,\..,\..,\..,\..,\..,\..,\..,\..=^..                                                                ,\..=^=^,`,`
//                                                        =^=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^=^..                                                                ,`=^=^*.....
//                                                        .....,`..,`..,`..,`..,`..,`..,`..,`..,`....*                                                                .,`.
//                                                        .=^..=^..=^..=^..=^..=^..=^..=^..=^..=^...*.                                                                ....
//                                                        ,\..,\..,\..,\..,\..,\..,\..,\..,\..,\..=^..
//                                                        ,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^=^..
//                                                        .,`..,`..,`..,`..,`..,`..,`..,`..,`..,`.....
//                                                        .........=^..=^..=^..=^..=^..=^..=^..=^.....
//                                                            .\/`,\..,\..,\..,\..,\..,\..,\..,\..,`,`
//                                                            .[,`,`=^,`=^,`=^,`=^,`=^,`=^,`=^,`=^....
//                                                                .,`..,`..,`..,`..,`..,`..,`..,`.
//                                                                ................................
//                                                                    ,`,`.\/`.\/`.\/`,`,`,`,`
//   
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
int n;
const int mod=1e9+7; 
int f[N];
int op;
int lowbit(int x){
	return x&(-x);
}
void add(int pos,int val){
	while(pos<=op+20){
		f[pos]+=val;
		f[pos]%=mod;
		pos+=lowbit(pos);
	}
	return ;
}
int sum(int pos){
	int ans=0;
	while(pos){
		ans+=f[pos];
		ans%=mod;
		pos-=lowbit(pos);
	}
	return ans;
}
struct node{
	int x,y;
}a[N];
bool cmp(node a,node b){
	if(a.y==b.y) return a.x<b.x;
	return a.y<b.y;
}
set<int>s;
map<int,int>p;
void solve(){
	int n,m;
	cin>>n>>m; 
	int fx=0,fy=0;
	for(int i=1;i<=m;++i){
		cin>>a[i].x>>a[i].y;
		if(a[i].x==0) fx++;
		if(a[i].y==n) fy++;
	}
	if(fx==0||fy==0){
		cout<<"0\n";
		return ;
	}
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=m;++i){
		s.insert(a[i].x);
		s.insert(a[i].y);
	}
	for(auto i=s.begin();i!=s.end();++i){
		if(p[*i]==0) p[*i]=++op;
	}
	add(1,1);
	for(int i=1;i<=m;i++){
		int dx=p[a[i].x];
		int dy=p[a[i].y];
		int pp=((sum(dy-1)-sum(dx-1))%mod+mod)%mod;
		add(dy,pp);
	}
	int res=((sum(p[n])-sum(p[n]-1))%mod+mod)%mod;
	cout<<res<<'\n';
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值