题目链接:传送门

题目大意:给你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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题

    A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Centos 6.4 python 2.6 升级到 2.7一起的MySQLdb不能使用的解决问题

    查看python的版本#python -V Python 2.6.6 1.下载Python-2.7.3#wget http://python.org/ftp/python/2.7.3/Python-2 ...

  2. Linux命令-网络命令:netstat

    netstat -tlun 查看本机监听tcp.udp显示IP地址和端口号 netstat -an 可以查看本机正在连接的所有信息 netstat -rn 可以查看本机网关 windows里面的net ...

  3. SUSE11SP3--安装svn

    SUSE上安装新版本的subversion是一件很麻烦的事情,涉及到的依赖太多,包括需要更新部分工具的版本. 为了以较小的代价安装subversion,我决定在SUSE11下安装 subversion ...

  4. 多校第九场Arithmetic Sequence题解

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5400 题意:给定等差数列的差值d1,d2.问长度为n的数列中有多少个满足条件的子序列,条件为子序列中 ...

  5. Lintcode---线段树的构造

    线段树是一棵二叉树,他的每个节点包含了两个额外的属性start和end用于表示该节点所代表的区间.start和end都是整数,并按照如下的方式赋值: 根节点的 start 和 end 由 build  ...

  6. excel增加上一列的数值(日期)

    =TEXT(D2-1,"m月d日") 有年的话就是 =TEXT(D2-1,"yyyy年m月d日") D2就是参照日期

  7. InnoDB:文件

    Mysql中有多种类型的文件,每种类型的文件都有其特定的作用,下面就来说说: 参数文件:告诉Mysql实例数据库文件的位置,定义参数. 日志文件:Mysql实例对某种条件作出的响应写入文件,这个文件就 ...

  8. JS根据时间内容分组代码

    let newArr = []; res.data.data.forEach((address, i) => { let index = -1; let newDates = Date.pars ...

  9. js从数组中提取数字

    某班的成绩出来了,现在老师要把班级的成绩打印出来. 效果图: XXXX年XX月X日 星期X--班级总分为:81 格式要求: 1.显示打印的日期. 格式为类似“XXXX年XX月XX日 星期X” 的当前的 ...

  10. lua工具库penlight--06数据(一)

    这篇太长了,分了两部分.(这个是机器翻译之后我又校对了一下,以后的都这样,人工翻译太累了.) 读数据文件 首先考虑清楚,你的确需要一个自定义的文件读入器吗?如果是,你能确定有能力写好吗? 正确,稳健, ...