题目链接:传送门

题目大意:给你n个区间,求任意k个区间交所包含点的数目之和。

题目思路:将n个区间都离散化掉,然后对于一个覆盖的区间,如果覆盖数cnt>=k,则数目应该加上 区间长度*(cnt与k的组合数) ans=ans+(len*C(cnt,k))%mod;

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <cstring>
  7. #include <stack>
  8. #include <cctype>
  9. #include <queue>
  10. #include <string>
  11. #include <vector>
  12. #include <set>
  13. #include <map>
  14. #include <climits>
  15. #define lson root<<1,l,mid
  16. #define rson root<<1|1,mid+1,r
  17. #define fi first
  18. #define se second
  19. #define ping(x,y) ((x-y)*(x-y))
  20. #define mst(x,y) memset(x,y,sizeof(x))
  21. #define mcp(x,y) memcpy(x,y,sizeof(y))
  22. using namespace std;
  23. #define gamma 0.5772156649015328606065120
  24. #define MOD 1000000007
  25. #define inf 0x3f3f3f3f
  26. #define N 200005
  27. #define maxn 1050
  28. typedef pair<int,int> PII;
  29. typedef long long LL;
  30.  
  31. int n,k,m,cnt;
  32. LL fac[N];
  33. struct Node{
  34. int x,v;
  35. bool operator<(const Node&a)const{
  36. if(x==a.x)return v>a.v;
  37. return x<a.x;
  38. }
  39. }node[N<<];
  40. int a[N<<],sum[N<<];
  41. int has[N<<];
  42. LL ksm(LL a,LL b){
  43. LL res=;
  44. while(b){
  45. if(b&)res=res*a%MOD;
  46. b>>=;
  47. a=a*a%MOD;
  48. }
  49. return res;
  50. }
  51. LL C(LL n,LL m){
  52. if(n<m||m<)return ;
  53. LL s1=fac[n],s2=fac[n-m]*fac[m]%MOD;
  54. return s1*ksm(s2,MOD-)%MOD;
  55. }
  56. int main(){
  57. int i,j,group,x,y,v;
  58. fac[]=;cnt=;
  59. for(i=;i<N;++i)fac[i]=fac[i-]*i%MOD;
  60. scanf("%d%d",&n,&k);
  61. for(i=;i<=n;++i){
  62. scanf("%d%d",&x,&y);
  63. node[cnt].x=x;node[cnt++].v=;
  64. node[cnt].x=y+;node[cnt++].v=-;
  65. }
  66. sort(node,node+cnt);
  67. LL ans=,la,num=; ///la是区间左端点
  68. for(i=;i<cnt;++i){
  69. if(num>=k) ans=(ans+(node[i].x-la*1ll)*C(num,k))%MOD;
  70. la=node[i].x;
  71. num+=node[i].v;
  72. }
  73. printf("%I64d\n",ans);
  74. return ;
  75. }

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. 系统流畅/性能受限 谷歌Nexus4详细评测

    http://mobile.it168.com/a2012/1220/1437/000001437938_8.shtml

  2. 异常:Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z/Caused by: java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreign

    Spring3.0 + Hibernate3.5:启动服务器报:Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany. ...

  3. linux磁盘满时,如何定位并删除文件

    原文链接: http://www.cnblogs.com/yinxiangpei/articles/4211743.html @1.一般情况   一般情况下先df看一下,然后cd到要满的盘,执行: d ...

  4. C# 共享内存(转)

    以下是一个C#操作内存的一个类,只要将下面的类添加到相应的项目中,该项目就可以对内存进行直接操作! using System.Runtime.InteropServices;    //添加如下命名空 ...

  5. unity3d的NGUI简易登录界面

    1.拖两个文本框和一个按钮在界面上,并做相应的重命名处理,结果如下图: 2.新建一个脚本,附加到“Login”上,脚本内容如下: public UIInput name; public UIInput ...

  6. C# DateTime的11种构造函数 [Abp 源码分析]十五、自动审计记录 .Net 登陆的时候添加验证码 使用Topshelf开发Windows服务、记录日志 日常杂记——C#验证码 c#_生成图片式验证码 C# 利用SharpZipLib生成压缩包 Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库

    C# DateTime的11种构造函数   别的也不多说没直接贴代码 using System; using System.Collections.Generic; using System.Glob ...

  7. mysql事务块处理

    begin ,rollback,commit .当然有的人用begin /begin work .推荐用START TRANSACTION 是SQL-99标准启动一个事务. start transac ...

  8. unity5, assert

    assert可以实现“三步一岗五步一哨”可以说是保证代码正确性(安全编程)的最有力工具.在用c++写程序的时候assert语句总是要占整个程序的大部分篇幅. 但是转到unity c#,一开始没找到as ...

  9. layui基础上的tree菜单动态渲染;

    var layout=[ { title:'脚本对象名称', treeNodes:true, headerClass:'value_col', colClass:'value_col', style: ...

  10. ListView嵌套GridView使用详解及注意事项

    ListView嵌套GridView即ListView的每个Item中都包含一个GridView:需要注意的是由于ListView和GridView都是可滑动的控件. 所以需要自定义GridView, ...