题意:
给定一个数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();
}
}