# 代码

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N = 2e5+5;
const int MOD = 1e9+7;

int l[N], r[N];
int sum[N*2];
int disc[N*2];
int fac[N];
int n, k;

LL powmod(LL a,LL b) {LL res=1;a%=MOD;for(; b; b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
LL inverse(LL a) {return powmod(a, MOD-2);}

int C(int n, int m) {
if (n < m) return 0;
return (LL)fac[n] * inverse(fac[m]) % MOD * inverse(fac[n-m]) % MOD;
}

int main() {
fac[0] = 1;
for (int i = 1; i < N; i++) {
fac[i] = ((LL)fac[i-1] * i) % MOD;
}

while (scanf("%d%d", &n, &k) == 2) {
int tot = 0;
for (int i = 0; i < n; i++) {
scanf("%d%d", l+i, r+i);
disc[tot++] = l[i];
disc[tot++] = ++r[i];
}
sort(disc, disc + tot);
tot = unique(disc, disc + tot) - disc;

for (int i = 0; i < n; i++) {
int l = lower_bound(disc, disc + tot, ::l[i]) - disc;
int r = lower_bound(disc, disc + tot, ::r[i]) - disc;
sum[l]++;
sum[r]--;
}

int ans = 0;
for (int i = 1; i < tot; i++) {
sum[i] += sum[i-1];
ans = (ans + (LL)C(sum[i-1], k) * (disc[i] - disc[i-1])) % MOD;
}
printf("%d\n", ans);
memset(sum, 0, sizeof sum);
}
return 0;
}

• 点赞 1
• 评论
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

ned_chu

你的鼓励将是我创作的最大动力

C币 余额
2C币 4C币 6C币 10C币 20C币 50C币
• 一键三连

点赞Mark关注该博主, 随时了解TA的最新博文