B. Karen and Coffee
time limit per test 2.5 seconds
memory limit per test 512 megabytes
input standard input
output standard output

To stay woke and attentive during classes, Karen needs some coffee!

Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe".

She knows n coffee recipes. The i-th recipe suggests that coffee should be brewed between li and ri degrees, inclusive, to achieve the optimal taste.

Karen thinks that a temperature is admissible if at least k recipes recommend it.

Karen has a rather fickle mind, and so she asks q questions. In each question, given that she only wants to prepare coffee with a temperature between a and b, inclusive, can you tell her how many admissible integer temperatures fall within the range?

Input

The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively.

The next n lines describe the recipes. Specifically, the i-th line among these contains two integers li and ri (1 ≤ li ≤ ri ≤ 200000), describing that the i-th recipe suggests that the coffee be brewed between li and ri degrees, inclusive.

The next q lines describe the questions. Each of these lines contains a and b, (1 ≤ a ≤ b ≤ 200000), describing that she wants to know the number of admissible integer temperatures between a and b degrees, inclusive.

Output

For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.

Examples
Input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
Output
3
3
0
4
Input
2 1 1
1 1
200000 200000
90 100
Output
0
Note

In the first test case, Karen knows 3 recipes.

  1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.
  2. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.
  3. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.

A temperature is admissible if at least 2 recipes recommend it.

She asks 4 questions.

In her first question, she wants to know the number of admissible integer temperatures between 92 and 94 degrees, inclusive. There are 3: 92, 93 and 94 degrees are all admissible.

In her second question, she wants to know the number of admissible integer temperatures between 93 and 97 degrees, inclusive. There are 3: 93, 94 and 97 degrees are all admissible.

In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.

In her final question, she wants to know the number of admissible integer temperatures between 90 and 100 degrees, inclusive. There are 4: 92, 93, 94 and 97 degrees are all admissible.

In the second test case, Karen knows 2 recipes.

  1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.
  2. The second one, "What good is coffee that isn't brewed at at least 36.3306 times the temperature of the surface of the sun?", recommends brewing the coffee at exactly 200000 degrees.

A temperature is admissible if at least 1 recipe recommends it.

In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.

题解:

首先预处理出c[i]表示第i位的次数。

然后维护一个线段树,c[i]>=m时就加到线段树里面去。

线段树可以保证这道题目不超时。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int a[],mmax,n,m,l;
int sgm[],root,lazy[];
int ll(int x){return x<<;}
int rr(int x){return x<<|;}
void update(int root,int left,int right,int l,int r,int v)
{
if(l<=left&&right<=r)
{
lazy[root]+=v;
return;
}
sgm[root]=sgm[root]+v*(min(r,right)-max(left,l)+);
int m=(left+right)>>;
if(l<=m)update(ll(root),left,m,l,r,v);
if(r>m)update(rr(root),m+,right,l,r,v);
return;
}
int query(int root,int left,int right,int l,int r)
{
if(l<=left&&right<=r)return sgm[root]+lazy[root]*(right-left+);
if(right<l||left>r)return ;
int m=(left+right)>>;
return query(ll(root),left,m,l,r)+query(rr(root),m+,right,l,r)+lazy[root]*(min(r,right)-max(left,l)+);
}
int main()
{
int i,j;
scanf("%d%d%d",&n,&m,&l);
for(i=;i<=n;i++)
{
int c,d;
scanf("%d%d",&c,&d);
mmax=max(mmax,d);
a[c]++;a[d+]--;
}
for(i=;i<=mmax;i++)
{
a[i]=a[i]+a[i-];
if(a[i]>=m)update(,,mmax,i,i,);
}
for(i=;i<=l;i++)
{
int c,d;
scanf("%d%d",&c,&d);
printf("%d\n",query(,,mmax,c,d));
}
return ;
}

最新文章

  1. 使用Xunit进行单元测试
  2. 小菜学习Winform(三)Socket点对点通信
  3. DataTable数据检索的性能分析(转寒江独钓)
  4. Vault插件示例--Vault Explorer与Thin Client的集成。
  5. iOS学习笔记---oc语言第八天
  6. 创建线程(Background Thread)的N种方式
  7. PHP计算2点经纬度之间的距离
  8. 从壹开始前后端分离【 .NET Core2.0 +Vue2.0 】框架之九 || 依赖注入IoC学习 + AOP界面编程初探
  9. 服务化改造实践 | 如何在 Dubbo 中支持 REST
  10. caffe分类
  11. IEDA的程序调试debug
  12. PID 通俗解释
  13. React Native小白入门学习路径——二
  14. Xcode - 因为证书问题经常报的那些错
  15. JAVA 重写equals和重写hashCode
  16. 【Java】【异常】
  17. C# ie通过打印控件点打印,总是弹出另存为xps的对话框
  18. 基于NOPI的Execl模板转换类,直接将Execl模板转换对应的Entity
  19. [置顶] 【机器学习PAI实践十一】机器学习PAI为你自动写歌词,妈妈再也不用担心我的freestyle了(提供数据、代码
  20. 【BZOJ2004】[HNOI2010]Bus 公交线路

热门文章

  1. BFC块级格式上下文
  2. Nginx 反向代理&amp;负载均衡
  3. python中的一些小知识
  4. Docker - 访问容器
  5. makefile文件模板介绍
  6. Ubuntu14.04安装samba
  7. mac Ubuntu 设置快捷进入目录
  8. 高性能mysql(二)——mysql的存储引擎
  9. 开涛spring3(12.2) - 零配置 之 12.2 注解实现Bean依赖注入
  10. javaWeb学习总结(8)- JSP属性范围(5)