D - Rescue Nibel!(组合数+线段交)

//1<=b<=a<=1e5 ,Cab mod (1e9+7)
#include <iostream>
#include <algorithm>
#define ll long long 
using namespace std;
const int N=300010,mod=998244353;
ll fact[N],infact[N];
struct P{
	int	num,v;
}a[N];
ll ans=0;
vector<P> v;
bool cmp(P x,P y){
	if(x.num==y.num)
		return x.v>y.v;
	else
		return x.num<y.num;
}
ll qmi(ll a,ll b,ll m)
{
    int ans=1;
    while(b)
    {
        if(b&1) ans=(ll)ans*a%m;
        a=(ll)a*a%m;
        b>>=1;
    }
    return ans;
}
ll cc(ll a,ll b){
	if(b>a) return 0;
	return fact[a]*infact[b]%mod*infact[a-b]%mod;
}
int main()
{
    fact[0]=infact[0]=1;
    for(int i=1;i<N;i++)
    {
        fact[i]=(ll)fact[i-1]*i%mod;//求阶乘 
        infact[i]=(ll)infact[i-1]*qmi(i,mod-2,mod)%mod;//求i阶乘逆元 
    } 
    int n,k;
    scanf("%d%d",&n,&k);
    while(n--)
    {
    	int x,y;
        scanf("%d%d",&x,&y);
        P t={x,1};
        v.push_back(t);
        t={y,-1};
        v.push_back(t);
    }
    sort(v.begin(),v.end(),cmp);
    int cnt=0;
    for(auto i:v){
    	if(i.v==1) ans=(ans+cc(cnt,k-1))%mod; 
    	cnt+=i.v;
	}
	printf("%lld\n",ans);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值