题目链接:传送门

题目大意:给你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. JavaScript入门:002—JS代码放置的位置

    JavaScript在页面中使用,那么这些JS代码应该放在什么位置呢?以下来看一下. 一般来说有两种方式.写在界面上和使用.js文件.1.1界面上的Head部分能够直接放在head标签内,例如以下代码 ...

  2. js 复制内容到粘贴板的兼容性

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs& ...

  3. asp.net 抓取新闻

    前台页面: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  4. 几种适配器&观察者&ListView之间的那点事

    android中的几种适配器&观察者&ListView 1.我们知道Android中的Adapter类是处于ListView和数据源之间的数据总线,它负责为ListView提供数据. ...

  5. 创建cocos2d-x+lua项目

    1>     创建cocos2d-x+lua项目 进入到cocos2d-x-2.1.5\tools\project-creator文件夹运行下面命令: python create_project ...

  6. C#面试基础问题0

    传入某个属性的set方法的隐含参数的名称是什么?value,它的类型和属性所声名的类型相同. 如何在C#中实现继承?在类名后加上一个冒号,再加上基类的名称. C#支持多重继承么?不支持.可以用接口来实 ...

  7. PHP扩展开发及内核应用(未完)

    转: https://github.com/walu/phpbook

  8. Decoration1:Spring-boot基础实现

    前段时间发布的Traveller项目,花费了不少精力,但是效果并不如意,根源在于瀑布式的开发思想不适合这种独立的学习项目.在项目初始就规划一个全面的web系统,,因为预设了一个前景,在心理上会想尽快看 ...

  9. [Java Web]Hibernate基础总结(四)

    性能优化 在大数据量遍历时(比如查找消息敏感词),须要手动使用clear方法释放缓存中的数据,防止缓存中数据过多浪费内存. 1+N问题:将Fetch设为LAZY能够在须要时才发出sql语句,或者设置B ...

  10. nginx vhosts rewrite 独立文件的方式出现

    [root@web01 /]# cat /app/server/nginx/conf/nginx.conf user www www; worker_processes ; error_log /ap ...