CF101B.Buses

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:265MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they follow from Gerald's home. The bus stop by Gerald's home has number 0 and the bus stop by the school has number n.

There are m buses running between the house and the school: the i-th bus goes from stop s__i to t__i (s__i < t__i), visiting all the intermediate stops in the order in which they follow on the segment. Besides, Gerald's no idiot and he wouldn't get off the bus until it is still possible to ride on it closer to the school (obviously, getting off would be completely pointless). In other words, Gerald can get on the i-th bus on any stop numbered from s__i to t__i - 1 inclusive, but he can get off the i-th bus only on the bus stop t__i.

Gerald can't walk between the bus stops and he also can't move in the direction from the school to the house.

Gerald wants to know how many ways he has to get from home to school. Tell him this number. Two ways are considered different if Gerald crosses some segment between the stops on different buses. As the number of ways can be too much, find the remainder of a division of this number by 1000000007 (109 + 7).

小男生杰拉尔德就读的学校离他家很远,因此他每天必须乘坐公交车上学。从家到学校的路线是一条直线线段,该线段上恰好有 n+1n+1 个公交站。这些站点按从杰拉尔德家到学校的顺序依次编号为整数 00 到 nn:杰拉尔德家所在的站点编号为 00,学校所在的站点编号为 nn。

共有 mm 辆公交车在线路(即从家到学校)之间运行:第 ii 辆公交车从站点 sis_i 开往站点 tit_i(其中 si<tis_i < t_i),并按线段上的顺序依次停靠所有中间站点。此外,杰拉尔德可不是傻瓜——他绝不会在还能继续乘该车更靠近学校时提前下车(显然,提前下车完全没意义)。换言之,杰拉尔德可以在编号为 sis_i 到 ti−1t_i - 1(含端点)的任意站点登上第 ii 辆公交车,但只能在站点 tit_i 下车。

杰拉尔德不能在公交站之间步行,也不能朝从学校返回家的方向移动。

杰拉尔德想知道他从家到达学校共有多少种不同的方式。请告诉他这个数目。若两种方式中杰拉尔德经过某两个相邻站点之间的路段所乘坐的公交车不同,则认为这两种方式不同。由于方案总数可能非常大,请输出该数对 10000000071000000007(即 109+710^9 + 7)取模的结果。

输入格式

The first line contains two space-separated integers: n and m (1 ≤ n ≤ 109, 0 ≤ m ≤ 105). Then follow m lines each containing two integers s__i, t__i. They are the numbers of starting stops and end stops of the buses (0 ≤ s__i < t__i ≤ n).

第一行包含两个以空格分隔的整数:nn 和 mm(1 ≤ n ≤ 1091 ≤ n ≤ 10^9,0 ≤ m ≤ 1050 ≤ m ≤ 10^5)。接下来是 mm 行,每行包含两个整数 sis_i、tit_i,分别表示公交车的起始站点编号和终点站点编号(0 ≤ si < ti ≤ n0 ≤ s_i < t_i ≤ n)。

输出格式

Print the only number — the number of ways to get to the school modulo 1000000007 (109 + 7).

输出唯一的数字——到达学校的方案数对 10000000071000000007(即 109+710^9 + 7)取模的结果。

输入输出样例

  • 输入#1

    2 2
    0 1
    1 2

    输出#1

    1
  • 输入#2

    3 2
    0 1
    1 2

    输出#2

    0
  • 输入#3

    5 5
    0 1
    0 2
    0 3
    0 4
    0 5

    输出#3

    16

说明/提示

The first test has the only variant to get to school: first on bus number one to the bus stop number one; then on bus number two to the bus stop number two.

In the second test no bus goes to the third bus stop, where the school is positioned. Thus, the correct answer is 0.

In the third test Gerald can either get or not on any of the first four buses to get closer to the school. Thus, the correct answer is 24 = 16.

第一次测试中,只有一种方式可以到达学校:先乘坐1路公交车到1号公交站,再乘坐2路公交车到2号公交站。

第二次测试中,没有任何一辆公交车开往第3号公交站(即学校所在位置),因此正确答案是0。

第三次测试中,Gerald可以选择乘坐或不乘坐前四辆公交车中的任意一辆,以更接近学校。因此,正确答案是 24=162^4 = 16。

输入解题思路,AI测评打分。不知道怎么写?

首页