# D - Rescue Nibel!(差分+组合数学+思维)详解

https://codeforces.com/contest/1420/problem/D

5 2
1 3
2 4
3 5
4 6
5 7

“terminate called after throwing an instance of 'std::bad_alloc'”

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e5+100;
typedef long long ll;
using namespace std;
const int inf=0x3f3f3f3f;
const int mod=998244353;
ll fac[maxn];
ll p=mod;
struct node{
ll x,c;
bool operator<(const struct node &T)const{
if(x==T.x) return c<T.c;
return x<T.x;
}
};
vector<node>q;
//bool cmp(node A,node B)
//{
//	if(A.x==B.x) return A.c<B.c;
//	return A.x<B.x;
//}
ll quick(ll a,ll b){
ll ans=1;
while(b){
if(b&1)ans=ans*a%p;
a=a*a%p;
b/=2;
}
return ans%p;
}
ll ccc(ll n,ll m){//求组合数
if(m>n) return 0;
return (fac[n] * quick(fac[m], p - 2) % p * quick(fac[n - m], p - 2) % p)%p ;
}
int main()
{
cin.tie(0);std::ios::sync_with_stdio(false);
//ccc(4,3);
fac[0] = 1;
for (ll i = 1; i <= maxn; i++){
fac[i] = fac[i - 1] * i % p;
}
ll n,k;cin>>n>>k;
for(ll i=1;i<=n;i++)
{
ll l,r;cin>>l>>r;
q.push_back({l,1});
q.push_back({r+1,-1});
}
sort(q.begin(),q.end());
ll cnt=0;ll res=0;//cnt表示当前枚举到的l前面还有多少个亮着的
for(auto i:q)
{
if(i.c==1) res=(res%mod+ccc(cnt,k-1)%mod)%mod;
cnt+=i.c;
}
cout<<res<<endl;
return 0;
}


• 点赞 1
• 评论 5
• 分享
x

海报分享

扫一扫，分享海报

• 收藏
• 手机看

分享到微信朋友圈

x

扫一扫，手机阅读

• 打赏

打赏

小菜鸡加油

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

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

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

08-26
05-27 1636
09-11 4205
11-30 1万+
02-24 6023
01-18 336