Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem
题目链接:传送门
题目大意:给你n个区间,求任意k个区间交所包含点的数目之和。
题目思路:将n个区间都离散化掉,然后对于一个覆盖的区间,如果覆盖数cnt>=k,则数目应该加上 区间长度*(cnt与k的组合数) ans=ans+(len*C(cnt,k))%mod;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 200005
#define maxn 1050
typedef pair<int,int> PII;
typedef long long LL; int n,k,m,cnt;
LL fac[N];
struct Node{
int x,v;
bool operator<(const Node&a)const{
if(x==a.x)return v>a.v;
return x<a.x;
}
}node[N<<];
int a[N<<],sum[N<<];
int has[N<<];
LL ksm(LL a,LL b){
LL res=;
while(b){
if(b&)res=res*a%MOD;
b>>=;
a=a*a%MOD;
}
return res;
}
LL C(LL n,LL m){
if(n<m||m<)return ;
LL s1=fac[n],s2=fac[n-m]*fac[m]%MOD;
return s1*ksm(s2,MOD-)%MOD;
}
int main(){
int i,j,group,x,y,v;
fac[]=;cnt=;
for(i=;i<N;++i)fac[i]=fac[i-]*i%MOD;
scanf("%d%d",&n,&k);
for(i=;i<=n;++i){
scanf("%d%d",&x,&y);
node[cnt].x=x;node[cnt++].v=;
node[cnt].x=y+;node[cnt++].v=-;
}
sort(node,node+cnt);
LL ans=,la,num=; ///la是区间左端点
for(i=;i<cnt;++i){
if(num>=k) ans=(ans+(node[i].x-la*1ll)*C(num,k))%MOD;
la=node[i].x;
num+=node[i].v;
}
printf("%I64d\n",ans);
return ;
}
Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem的更多相关文章
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化 排列组合
E. Mike and Geometry Problem 题目连接: http://www.codeforces.com/contest/689/problem/E Description Mike ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 【逆元求组合数 && 离散化】
任意门:http://codeforces.com/contest/689/problem/E E. Mike and Geometry Problem time limit per test 3 s ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化+逆元
E. Mike and Geometry Problem time limit per test 3 seconds memory limit per test 256 megabytes input ...
- Codeforces Round #410 (Div. 2)C. Mike and gcd problem
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...
- Codeforces Round #361 (Div. 2) C. Mike and Chocolate Thieves 二分
C. Mike and Chocolate Thieves 题目连接: http://www.codeforces.com/contest/689/problem/C Description Bad ...
- Codeforces Round #361 (Div. 2) B. Mike and Shortcuts bfs
B. Mike and Shortcuts 题目连接: http://www.codeforces.com/contest/689/problem/B Description Recently, Mi ...
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题
A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...
- Codeforces Round #361 (Div. 2)——B. Mike and Shortcuts(BFS+小坑)
B. Mike and Shortcuts time limit per test 3 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #361 (Div. 2)A. Mike and Cellphone
A. Mike and Cellphone time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- 【转贴】J2EE中的13种技术规范
J2EE平台由一整套服务(Services).应用程序接口(APIs)和协议构成,它对开发基于Web的多层应用提供了功能支持,下面对J2EE中的13种技术规范进行简单的描述(限于篇幅,这里只能进行简单 ...
- form表单中的id 与name的区别
以前经常写form表单时,不写id和name,总觉得没有什么用.后来一看后台套完的页面发现,他们都补上name,不知道所以然,就查了一下资料,吓我一跳,要是照我那样写根本不会有数据传到服务器.原来表单 ...
- CSS经验库
1.兼容360浏览器 字体大小设置 开发中需要使用em单位 font-size: 0.83em; font-family: "Arial"; -webkit-text-size-a ...
- CSDN开源夏令营 百度数据可视化实践 ECharts(8)
(1)前言 首先谢谢林峰老师,继续接着第七篇提到的内容.CSS布局确实非常累,感觉不好看了就的调整,总的看起来的高大上嘛.好了废话不再多说.今天主要就先解说一个页面的内容,对于CSS布局后面讲会具体的 ...
- python打包exe文件-ImportError: No module named 'queue'
我之前遇到的一个错误就是 File "site-packages\urllib3\packages\six.py", line 92, in __get__ File " ...
- C#颜色 Color.FromArgb ColorTranslator 16进制
//方法1: //引用命名空间 using System.Drawing; 16进制颜色代码转Color类型:ColorTranslator.FromHtml(color); Color类型转16进制 ...
- 终端I/O termios属性设置 tcsetattr设置(转)
终端I/O有两种不同的工作方式: 规范方式输入处理.在这种方式中,终端输入以行为单位进行处理.对于每个读要求,终端驱动程序最多返回一行. 非规范方式输入处理.输入字符不以行为单位进行装配. 如果不作特 ...
- 【问题记录】mybatis开启事务方法时,一级缓存可能引发的问题
首先,上代码: public void listMybatisModel() { List<MybatisModel> mybatisModels = mapper.listMybatis ...
- linux学习笔记11---命令more
more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就会 ...
- Macbook上Windows的触摸板设置工具
Macbook上用Boot Camp装了双系统后,没了触摸板的三指拖拽功能,滚动(scroll)也太过灵敏,装Boot Camp官方驱动也没用. 装了Trackpad++这个第三方驱动,就能完美实现M ...