Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化+逆元
3 seconds
256 megabytes
standard input
standard output
Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's definef([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that ). You are given two integers nand k and n closed intervals [li, ri] on OX axis and you have to find:
In other words, you should find the sum of the number of integer points in the intersection of any k of the segments.
As the answer may be very large, output it modulo 1000000007 (109 + 7).
Mike can't solve this problem so he needs your help. You will help him, won't you?
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 200 000) — the number of segments and the number of segments in intersection groups respectively.
Then n lines follow, the i-th line contains two integers li, ri ( - 109 ≤ li ≤ ri ≤ 109), describing i-th segment bounds.
Print one integer number — the answer to Mike's problem modulo 1000000007 (109 + 7) in the only line.
- 3 2
1 2
1 3
2 3
- 5
- 3 3
1 3
1 3
1 3
- 3
- 3 1
1 2
2 3
3 4
- 6
In the first example:
;
;
.
So the answer is 2 + 1 + 2 = 5.
思路:给你n条线段,把线段放进数轴每次处理每个点的贡献,端点另外算;
给两组数据
2 1
1 3
3 4
2 1
1 3
5 6
- #include<bits/stdc++.h>
- using namespace std;
- #define ll __int64
- #define esp 0.00000000001
- const int N=2e5+,M=1e6+,inf=1e9,mod=1e9+;
- struct is
- {
- ll l,r;
- }a[N];
- ll poww(ll a,ll n)//快速幂
- {
- ll r=,p=a;
- while(n)
- {
- if(n&) r=(r*p)%mod;
- n>>=;
- p=(p*p)%mod;
- }
- return r;
- }
- ll flag[N*];
- ll lisan[N*];
- ll sum[N*];
- ll zz[N*];
- int main()
- {
- ll x,y,z,i,t;
- scanf("%I64d%I64d",&x,&y);
- int ji=;
- for(i=;i<x;i++)
- {
- scanf("%I64d%I64d",&a[i].l,&a[i].r);
- flag[ji++]=a[i].l;
- flag[ji++]=a[i].l+;
- flag[ji++]=a[i].r;
- flag[ji++]=a[i].r+;
- }
- sort(flag+,flag+ji);
- ji=unique(flag+,flag+ji)-(flag+);
- int h=;
- for(i=;i<=ji;i++)
- lisan[h++]=flag[i];
- memset(flag,,sizeof(flag));
- for(i=;i<x;i++)
- {
- int l=lower_bound(lisan+,lisan+h,a[i].l)-lisan;
- int r=lower_bound(lisan+,lisan+h,a[i].r)-lisan;
- flag[l]++;
- flag[r+]--;
- }
- for(i=;i<=h;i++)
- sum[i]=sum[i-]+flag[i];
- ll ans=;
- memset(zz,,sizeof(zz));
- zz[y]=;
- for (i=y+;i<=*x;i++) zz[i]=((zz[i-]*i%mod)*poww(i-y,mod-))%mod;
- for(i=;i<h;i++)
- {
- int zh=min(sum[i],sum[i-]);
- ans+=zz[zh]*(lisan[i]-lisan[i-]-);
- ans+=zz[sum[i]];
- ans%=mod;
- }
- printf("%I64d\n",ans);
- return ;
- }
Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem 离散化+逆元的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #361 (Div. 2) E. Mike and Geometry Problem
题目链接:传送门 题目大意:给你n个区间,求任意k个区间交所包含点的数目之和. 题目思路:将n个区间都离散化掉,然后对于一个覆盖的区间,如果覆盖数cnt>=k,则数目应该加上 区间长度*(cnt ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #361 (Div. 2) A. Mike and Cellphone 水题
A. Mike and Cellphone 题目连接: http://www.codeforces.com/contest/689/problem/A Description While swimmi ...
- 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 ...
- 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 ...
随机推荐
- 十個必用的 Vim Plugin
◎ The NERD Tree 操作 Vim 時,通常都在 Terminal 底下作用,無法像一般的 GUI 應用程式可以以樹狀目錄來瀏覽檔案. The NERD Tree 是一將檔案目錄 ...
- Mybatis在Maven项目中使用
Mybatis概览 ORM是什么? ORM是Object Realtion Mapping的缩写,顾名思义,即对象关系映射. ORM是一种以面向对象的方式来进行数据库操作的技术.Web开发中常用的语言 ...
- java7(3)——增强的catch之自动释放资源
跟mutilcatch一样,java7提供了自动释放资源的方法,但还是很少看到人使用,估计是麻烦去重写close方法.不过jdk内部一些类已经改成使用增强的catch来释放资源的写法,所以我们有必要了 ...
- 【足迹C++primer】38、关联容器操作(2)
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/cutter_point/article/details/35244805 关联容器操作(2) map ...
- J.U.C Atomic(二)基本类型原子操作
java.util.concurrent.atomic包中对基本类型进行原子操作的类有:AtomicInteger.AtomicBoolean.AtomicLong. 下面通过一个测试程序来验证一下A ...
- Jmeter添加变量的四种方法
一.在样本中添加同请求一起发送的参数.根据服务器设置的数据类型,来添加不同类型的参数 二.用户定义的变量 1.创建:添加->配置元件->用户定义的变量 2.作用:当前的线程组内所有Samp ...
- Webservice介绍
一. Socket和Http通信协议介绍 1. Socket协议简单介绍 Socket位于传输层,它是对Tcp/ip协议的实现,包含TCP/UDP,它是所有通信协议的基础,如下为Socket通 ...
- Selenium的PageFactory & PageObject 在大型项目中的应用
因为最近遇到的技术问题一直没找到可行的解决办法,一直在翻看selenium的源代码,之前写测试代码的时候就是拿来即用,写什么功能啊,就按手动的操作步骤去转换,近日看到一个文章,又去wiki上查了查,觉 ...
- PKU 2002 Squares(二维点哈希+平方求余法+链地址法)
题目大意:原题链接 给定平面上的N个点,求出这些点一共可以构成多少个正方形. 解题思路: 若正方形为ABCD,A坐标为(x1, y1),B坐标为(x2, y2),则很容易可以推出C和D的坐标.对于特定 ...
- Hbase环境安装
说明: (Hbase依赖于HDFS和zookeeper) 参考我的博客: https://www.cnblogs.com/654wangzai321/p/8603498.html https://ww ...