Description

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, nk (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.

Sample Input

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

Hint

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.

题目意思:女主为了得到最好的泡咖啡的温度,看了n本书,n本书推荐了n种的适合范围,她想要查询q次,a~b温度范围内有多少个温度是可以允许泡咖啡的时间(这个时间要求至少有k本数推荐过)。

解题思路:当时没有做到这一道题。。。。总的来说这一道题使用前缀和来做,这道题是不是有点像给气球刷颜色的那一类题。

N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
 
当时数据在做这一类题的时候,限于数据量的因素,使用了树状数字或者线段树这样的数据结构,这里就可以不去使用了。
 
  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #define maxs 200010
  5. using namespace std;
  6. int n,k,q;
  7. int a[maxs];
  8. int sum[maxs];
  9. int main()
  10. {
  11. int i,r,l;
  12. scanf("%d%d%d",&n,&k,&q);
  13. for(i=;i<n;i++)
  14. {
  15. scanf("%d%d",&l,&r);
  16. a[l]++;
  17. a[r+]--;
  18. }
  19. for(i=;i<maxs;i++)
  20. {
  21. a[i]+=a[i-];
  22. if(a[i]>=k)///满足至少有k本书推荐
  23. {
  24. sum[i]++;
  25. }
  26. }
  27. for(i=;i<maxs;i++)
  28. {
  29. sum[i]+=sum[i-];
  30. }
  31. for(i=;i<q;i++)
  32. {
  33. scanf("%d%d",&l,&r);
  34. printf("%d\n",sum[r]-sum[l-]);
  35. }
  36. return ;
  37. }

Karen and Coffee CF 816B(前缀和)的更多相关文章

  1. Karen and Coffee CodeForces - 816B (差分数组+预处理前缀和)

    To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...

  2. Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)

    http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...

  3. CF 816B Karen and Coffee【前缀和/差分】

    To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...

  4. CodeForces 816B Karen and Coffee(前缀和,大量查询)

    CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the ...

  5. 816B. Karen and Coffee 前缀和思维 或 线段树

    LINK 题意:给出n个[l,r],q个询问a,b,问被包含于[a,b]且这样的区间数大于k个的方案数有多少 思路:预处理所有的区间,对于一个区间我们标记其(左边界)++,(右边界+1)--这样就能通 ...

  6. codeforces 816B Karen and Coffee (差分思想)

    题目链接 816B Karen and Coffee 题目分析 题意:有个人在学泡咖啡,因此看了很多关于泡咖啡温度的书,得到了n种推荐的泡咖啡温度范围[L1,R1] ,此人将有k种做法推荐的温度记为可 ...

  7. Codeforces Round #419 (Div. 2) B. Karen and Coffee

    To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...

  8. Codeforces816B Karen and Coffee 2017-06-27 15:18 39人阅读 评论(0) 收藏

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

  9. CodeForces 816B 前缀和

    To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...

随机推荐

  1. SSM(SpringMVC+Spring+Mybatis)框架学习理解

    近期做到的项目中,用到的框架是SSM(SpringMVC+Spring+Mybatis).之前比较常见的是SSH.用到了自然得了解各部分的分工 spring mvc 是spring 处理web层请求的 ...

  2. c#网络加密传输

    网上已经有很多测试,我就不多说了.先说说我的测试. 1.net framework 都应该合适. 2.RSACryptoServiceProvider类在.net core 下无法调用xml导出方法( ...

  3. CentOS7 minimal(最小化安装)后增加的软件安装

    1.net-tools 安装,因为习惯使用ifconfig命令 2.wget安装,下载工具必不可少 3.vim安装,相比于vi个人更喜欢vim 4.yum-plugin-priorities安装,用于 ...

  4. 浅谈OSI七层网络模型和TCP/IP四层模型

    OSI七层网络模型 OSI(Open System Interconnection)开放系统互连参考模型是国际标准化组织(ISO)制定的一个用于计算机或通信系统间互联的标准体系. OSI七层模型 功能 ...

  5. 四、spring成长之路——springIOC容器(下)

    目录 5.spring注解开发(Spring扩展知识) 5.1定义配置类:@Configuration 声明一个类为IOC容器 @Bean定义一个Bean 5.2.按照条件进行注入 5.3.@Impo ...

  6. tp5多入口配置

    手册里可能有写,但不是特别清晰,在这给个实例,有两种方式: 1.多个入口文件: 将public下的index.php复制一份,粘贴.重命名为对应模块的名字,如admin: 编辑admin.php的内容 ...

  7. 面试:HashSet怎么判断重复

    HashSet是基于HashMap实现的,元素的值存储在key上,value的值所有元素都一样,都是这个 private static final Object PRESENT = new Objec ...

  8. Linux系统下连接校园网Drcom客户端教程(广东工业大学)

    这篇教程写给想要学习Linux系统或者在Linux系统下有需要使用Drcom上网的同学,在我疯狂踩坑,经过n多次的刷机装机实验,体验不同发行版本的linux系统后,终于懂得怎么连接上drcom,想想连 ...

  9. Using Angular 1.x With ES6 and Webpack

    http://angular-tips.com/blog/2015/06/using-angular-1-dot-x-with-es6-and-webpack/

  10. 虚拟机安装与Linux命令的学习 ——20155215宣言

    一.虚拟机的安装 虚拟机的安装对我来说真可谓是一波三折.打开老师发布的安装教程,简单地浏览了一下,主要步骤都有图文解说.我本来以为这个安装按部就班即可,可哪知道,问题一个接着一个出现. 问题1 在我下 ...