题目链接:传送门

题目大意:给你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. 微信小程序挑一挑辅助

    1.窗体 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;usi ...

  2. XML - 十分钟了解XML结构以及DOM和SAX解析方式

    引言 NOKIA 有句著名的广告语:"科技以人为本".不论什么技术都是为了满足人的生产生活须要而产生的.详细到小小的一个手机.里面蕴含的技术也是浩如烟海.是几千年来人类科技的结晶, ...

  3. Ubuntu11.04中如何将pycharm添加到系统的“应用程序”菜单里 (pycharm已成功安装)

    默认排序 Stu.zhouyc   21 人赞同了该回答 tools---->create desktop entry...不是很方便吗? 发布于 2016-04-09 21添加评论 分享 收藏 ...

  4. linux下使用dd命令写入镜像文件到u盘

    1.使用 df -h ,查看一下当前各个磁盘 user@host ~/ $ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 119 ...

  5. BootCamp支持软件6

    最新版本的 Boot Camp 6 苹果驱动支持的机型列表 苹果官方已经公布了 BootCamp 6 驱动支持的机型列表了,基本上 2012 年后的 Macbook / Pro / Air / iMa ...

  6. 解决eclipse无法打开:Failed to load the JNI shared library

    64位系统安装了64位的eclipse,但是jdk是32位的 总之就是eclipse跟jdk搭配不上,所以解决的时候注意这一点

  7. PL/SQL查询结果中文乱码

    新建变量,设置变量名:NLS_LANG,变量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK,确定即可

  8. VMware虚拟机实用经验总结十一条

    转:http://article.pchome.net/content-948404.html 1.VMware虚拟机实用经验之支持的Guest OS: VMWare支持如下Guest OS:MS-D ...

  9. 【Mac + Appium + Python3.6学习(四)】之常用的IOS自动化测试API总结

    环境: Appium:1.9.1 Appium-desktop:1.7.1 Xcode:10.0 IOS:iPhone5S(10.3.3) Mac:10.13.6 ①获取手机屏幕size:长.宽 &l ...

  10. JAVA图像缩放处理

    http://www.blogjava.net/kinkding/archive/2009/05/23/277552.html ———————————————————————————————————— ...