题目链接:传送门

题目大意:给你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. 自己Cookie写的自动登录功能 包含BASE64 和MD5的使用

    sql表 username  password字段 User类 有 id username password等字段 Service有一函数 @Override public User findUser ...

  2. python导入模块的两种方式

    第一种 from support import * 这种方式导入后可以直接调用(有命名冲突问题)命名冲突后定义的覆盖前定义的 如果在函数导入前定义 则导入函数覆盖 否则相反 if __name__ = ...

  3. 转:微软分布式云计算框架Orleans

    http://www.cnblogs.com/ants/p/5122068.html 一种构建分布式. 高规模(伸缩)的应用程序 微软对奥尔良计划(Project Orleans)云计算框架开源.奥尔 ...

  4. ui-router参数传递

    基本参数: ‘/user/:id' '/user/{id}' '/user/{id:int}' 使用正则表达式: '/user/{id:[0-9]{1,8}' '/user/{id:.*}' '/us ...

  5. 程序包javax.servlet.annotation不存在

    1.错误描写叙述 [INFO] Scanning for projects... [INFO] [INFO] --------------------------------------------- ...

  6. 多线程-Executor,Executors,ExecutorService,ScheduledExecutorService,AbstractExecutorService

    引用 系统启动一个新线程的成本是比较高的,因为涉及与操作系统交互.使用线程池可以很好地提高性能,尤其是当程序中需要创建大量生存期很短的线程时,更应该考虑使用线程池.线程池在系统启动时即创建大量空闲的线 ...

  7. 多线程-BlockingQueue,Array[Linked]BlockingQueue,DelayQueue,PriorityBlockingQueue,SynchronousQueue

    阻塞场景 BlockingQueue阻塞队列,阻塞的情况主要有如下2种: 1. 当队列满了,进行入队操作阻塞 2. 当队列空了,进行出队操作阻塞 阻塞队列主要用在生产者/消费者模式中,下图展示了一个线 ...

  8. thread_线程间协作:wait、notify、notifyAll和Condition

    经典模式:生产者-消费者模型:当队列满时,生产者需要等待队列有空间才能继续往里面放入商品,而在等待的期间内,生产者必须释放对临界资源(即队列)的占用权.因为生产者如果不释放对临界资源的占用权,那么消费 ...

  9. C++语言基础(20)-模板的非类型参数

    一.在函数模板中使用非类型参数 #include <iostream> using namespace std; template<class T> void Swap(T & ...

  10. java使用lambda表达式对List集合进行操作(JDK1.8)

    1. 使用lambda表达式对List集合进行操作(JDK1.) List<TreeDto> collect = list.stream().filter(item -> item. ...