codeforces 361 div2 E. Mike and Geometry Problem
来源:互联网 发布:淘宝达人淘入口在哪里 编辑:程序博客网 时间:2024/06/09 19:49
假如每个点被n1条线段覆盖求k个线段覆盖它的方案数 显然C(n1,k)
点太多那就离散化以线段的形式来求最多20万条线段求覆盖线段数更合理
#include<cstdio>#include<iostream>#include<algorithm>#include<vector>#define mod 1000000007ll#define LL long long#define maxn 200010using namespace std;struct node{ LL l,r;}no[maxn];LL d[2*maxn],f[maxn],cnt = 0,sum[2*maxn] = {0},n,k;void init(){ f[0] = 1; for(int i=1;i<maxn;i++) { f[i] = f[i-1]*(LL)i; f[i] %= mod; }}LL modPow(LL n,LL m){ LL ans = 1; while(m) { if(m&1ll)ans*=n; ans%=mod; n*=n; n%=mod; m>>=1; } return ans;}LL C(LL n,LL m){ return f[n]*modPow(f[m]*f[n-m]%mod,mod-2)%mod;}int main(){ init(); scanf("%I64d %I64d",&n,&k); for(int i=0;i<n;i++) scanf("%I64d %I64d",&no[i].l,&no[i].r); for(int i=0;i<n;i++) { d[cnt++] = no[i].l; d[cnt++] = no[i].r+1; } sort(d,d+cnt); cnt = unique(d,d+cnt)-d; for(int i=0;i<n;i++) { LL pre = lower_bound(d,d+cnt,no[i].l)-d; sum[pre]++; pre = lower_bound(d,d+cnt,no[i].r+1)-d; sum[pre]--; } LL sum1 = sum[0],ans = 0; for(int i=1;i<cnt;i++) { LL temp = 0; if(sum1>=k) temp = (d[i]-d[i-1])%mod*C(sum1,k)%mod; ans+=temp; ans%=mod; sum1+=sum[i]; } printf("%I64d\n",ans); return 0;}
0 0
- codeforces 361 div2 E. Mike and Geometry Problem
- Codeforces #361 E. Mike and Geometry Problem 数学
- Codeforces Round #361 (Div. 2)E. Mike and Geometry Problem
- Codeforces 689E Mike and Geometry Problem(组合数学)
- Codeforces 689E Mike and Geometry Problem 思维
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem (离散化)
- Codeforces 689E Mike and Geometry Problem(离散化+懒标记)
- [Codeforces 689E] Mike and Geometry Problem (贡献计数+静态区间更新)
- Codeforces 689E Mike and Geometry Problem【离散化+线段树+组合数】
- CF 361 E. Mike and Geometry Problem (排列组合+乘法逆元)
- codeforces689E: Mike and Geometry Problem
- Mike and gcd problem-codeforces-Round 410 Div2-C
- codeforces round410 div2 C.Mike and gcd problem (数学)
- Mike and gcd problem CodeForces
- Codeforces #305 div2 E. Mike and Foam 数论 容斥原理
- CodeForces #187.div2.problem E
- Codeforces689E Mike and Geometry Problem(数学+算贡献)
- CF689E:Mike and Geometry Problem(组合数)
- Mybaits深入了解(三)----mybatis开发Dao的方法
- js实现文件上传—带进度条
- jquery 跨域post 问题解决
- 自定义光标
- 周易六十四卦——大壮卦
- codeforces 361 div2 E. Mike and Geometry Problem
- NB-IoT标准确定,物联网将腾飞
- C++中使用STL的hashmap
- opencv 截取轮廓中的图像——实现PS中的抠图功能 Opencv extract area circled by contour
- 表达式合法判断
- opencv_关于特征点匹配的数据结构
- C/C++中static关键字详解
- UVA673Parentheses Balance
- Java通过反射获取带参数构造方法并使用