测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A10374. Mike and Geometry Problem

编程题 普及/提高-

题目描述

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 ![](/uploads/acgo/image/07e99c4c91500137_4f0c48b2df8a.jpeg)). You are given two integers $n$ and $k$ and $n$ closed intervals $[l_{i},r_{i}]$ on $OX$ axis and you have to find:

![](/uploads/acgo/image/f7d7d2218463fca7_5073d995ff89.jpeg)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$ ( $10^{9}+7$ ).

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

输入格式

The first line contains two integers $n$ and $k$ ( $1<=k<=n<=200000$ ) — 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}$ $(-10^{9}<=l_{i}<=r_{i}<=10^{9})$ , describing $i$ -th segment bounds.

输出格式

Print one integer number — the answer to Mike's problem modulo $1000000007$ ( $10^{9}+7$ ) in the only line.

输入输出样例

输入 #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:

![](/uploads/acgo/image/3f46c9439471ac40_fa89ed9b3eac.jpeg);

![](/uploads/acgo/image/3d0b6a558658f50c_c7d6b1f72105.jpeg);

![](/uploads/acgo/image/20c865a0cfd0e352_f5b1447e12ec.jpeg).

So the answer is $2+1+2=5$ .
上一题 去做题 下一题