Codeforces Round #361 (Div. 2) 套题
2016-07-11 14:22
155 查看
A - Mike and Cellphone
问有没有多解,每个点按照给出的序列用向量法跑一遍
View Code
问有没有多解,每个点按照给出的序列用向量法跑一遍
#include <vector> #include <iostream> #include <queue> #include <cmath> #include <map> #include <cstring> #include <algorithm> #include <cstdio> using namespace std; typedef long long LL; const int N=2e5+5; const LL mod=1e9+7; struct Segment{ int l,r; }p ; int pos[N*2],n,k,tot,a[N*2],b[2*N]; LL dp ,fac ,inv ; LL quick_pow(LL a,LL num){ LL ret=1; while(num){ if(num&1)ret=(ret*a)%mod; num>>=1; a=(a*a)%mod; } return ret; } LL C(LL n,LL m){ return (fac *inv[n-m])%mod*inv[m]%mod; } int main() { scanf("%d%d",&n,&k); inv[0]=fac[0]=1; for(int i=1;i<=n;++i){ fac[i]=1ll*i*fac[i-1]%mod; inv[i]=quick_pow(fac[i],mod-2); } for(int i=1;i<=n;++i){ scanf("%d%d",&p[i].l,&p[i].r); pos[++tot]=p[i].l; pos[++tot]=p[i].r; } sort(pos+1,pos+1+tot); tot=unique(pos+1,pos+1+tot)-pos-1; for(int i=1;i<=n;++i){ p[i].l=lower_bound(pos+1,pos+1+tot,p[i].l)-pos; p[i].r=lower_bound(pos+1,pos+1+tot,p[i].r)-pos; ++a[p[i].l],--b[p[i].r]; } for(int i=1;i<=tot;++i){ a[i]+=a[i-1]; ++dp[a[i]]; if(i!=1)dp[a[i-1]]+=max(0,pos[i]-pos[i-1]-1); a[i]+=b[i]; } LL ret=0; for(int i=k;i<=n;++i){ ret=(ret+dp[i]*C(i,k)%mod)%mod; } printf("%I64d\n",ret); return 0; }
View Code
相关文章推荐
- leetcode.177. Nth Highest Salary
- 如何根据基类指针来判断这个基类是由那个子类转换而来!
- HTML5
- web,视频播放两种方法
- Java ConcurrentModificationException异常原因和解决方法
- UVA - 699 The Falling Leaves 二叉树
- oninput,onpropertychange,onchange的用法
- 字符串-401 - Palindromes
- Hibernate+JPA注解
- PHP 获取中国时间,即上海时区时间
- Javascript数组操作详细解答
- oracle列出两个日期间所有日期
- Mike and Cellphone
- POJ 2367 Genealogical tree【拓普排序】
- MAP
- Java并发编程:同步容器
- 第一篇博文~
- Linq To Entity多条件or查询处理
- nodejs 安装没有找到 configure
- 语义化标签