CF689E.Mike and Geometry Problem

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that ). You are given two integers n and k and n closed intervals [l__i, r__i] on OX axis and you have to find:

In other words, you should find the sum of the number of integer points in the intersection of any k of the segments.

As the answer may be very large, output it modulo 1000000007 (109 + 7).

Mike can't solve this problem so he needs your help. You will help him, won't you?

Mike 想为国际数学奥林匹克竞赛(IMO)做准备,但他不会几何,因此他的老师给了他一道有趣的几何题。我们定义函数 f([l, r])=r−l+1f([l,\,r]) = r - l + 1 表示闭区间 [l, r][l,\,r](其中 l≤rl \le r)中所含整数点的个数(即 )。现给定两个整数 nn 和 kk,以及 nn 个位于 OXOX 轴上的闭区间 [li, ri][l_i,\,r_i],你需要计算:

换言之,你需要求出:在所有 (nk)\binom{n}{k} 种选取 kk 个区间的方案中,每种方案所选 kk 个区间交集内的整数点个数之和。

由于答案可能非常大,请将结果对 10000000071000000007(即 109+710^9 + 7)取模后输出。

Mike 解不出这道题,所以他需要你的帮助。你愿意帮他吗?

输入格式

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of segments and the number of segments in intersection groups respectively.

Then n lines follow, the i-th line contains two integers l__i, r__i ( - 109 ≤ l__i ≤ r__i ≤ 109), describing i-th segment bounds.

第一行包含两个整数 nn 和 kk(1 ≤ k ≤ n ≤ 200 0001 \le k \le n \le 200\,000),分别表示线段的总数以及交集组中所含线段的数量。

接下来有 nn 行,其中第 ii 行包含两个整数 lil_i、rir_i(−109 ≤ li ≤ ri ≤ 109-10^9 \le l_i \le r_i \le 10^9),描述第 ii 条线段的左右端点。

输出格式

Print one integer number — the answer to Mike's problem modulo 1000000007 (109 + 7) in the only line.

在单独的一行中输出一个整数——Mike 问题的答案对 1000000007(109+710^9 + 7)取模的结果。

输入输出样例

  • 输入#1

    3 2
    1 2
    1 3
    2 3

    输出#1

    5
  • 输入#2

    3 3
    1 3
    1 3
    1 3

    输出#2

    3
  • 输入#3

    3 1
    1 2
    2 3
    3 4

    输出#3

    6

说明/提示

In the first example:

;

;

.

So the answer is 2 + 1 + 2 = 5.

在第一个例子中:

;

;

。

因此答案为 2+1+2=52 + 1 + 2 = 5。

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

首页