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
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

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个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
 
当时数据在做这一类题的时候,限于数据量的因素,使用了树状数字或者线段树这样的数据结构,这里就可以不去使用了。
 
 #include<cstdio>
#include<cstring>
#include<algorithm>
#define maxs 200010
using namespace std;
int n,k,q;
int a[maxs];
int sum[maxs];
int main()
{
int i,r,l;
scanf("%d%d%d",&n,&k,&q);
for(i=;i<n;i++)
{
scanf("%d%d",&l,&r);
a[l]++;
a[r+]--;
}
for(i=;i<maxs;i++)
{
a[i]+=a[i-];
if(a[i]>=k)///满足至少有k本书推荐
{
sum[i]++;
}
}
for(i=;i<maxs;i++)
{
sum[i]+=sum[i-];
}
for(i=;i<q;i++)
{
scanf("%d%d",&l,&r);
printf("%d\n",sum[r]-sum[l-]);
}
return ;
}

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. ionic 环境搭建

    1.安装nodejs (8.4.0) 下载地址 https://nodejs.org/zh-cn/ 2.Java jdk  版本号  jdk1.8.0_121 3.安装 cordova npm ins ...

  2. JQuery简单总结(思维导图)

  3. windows7平台 nginx+python 环境搭建

    参考了这篇文章,感谢原文作者:https://blog.csdn.net/foxgod/article/details/78929201 最近正在学习Python,发现除了写一点py脚本在idlex上 ...

  4. python3 str各个功能记录

    capitalize() 将字符串的第一个字符转换为大写 center(width, fillchar) 返回一个指定的宽度 width 居中的字符串,fillchar 为填充的字符,默认为空格. c ...

  5. Wtrofms

    一.安装 安装:pip3 install wtforms 二.使用1(登录) from flask import Flask, render_template, request, redirect f ...

  6. PHP-学习笔记-进阶

    PHP-学习笔记-进阶 PHP类和对象之定义类的方法 访问控制的关键字代表的意义为: public:公开的 protected:受保护的 private:私有的 我们可以这样定义方法: class C ...

  7. 什么是PHP7中的孤儿进程与僵尸进程

    什么是PHP7中的孤儿进程与僵尸进程 基本概念 我们知道在unix/linux中,正常情况下,子进程是通过父进程创建的,子进程在创建新的进程.子进程的结束和父进程的运行是一个异步过程,即父进程永远无法 ...

  8. IDEA新建Web项目

    file->New project->输入项目名(例如这里输入HelloWeb) 选择JDK为合适版本->next ->finish即可 在新建的项目HelloWorld上右击 ...

  9. 【CS】知识索引汇总

    Chapter 7 hello.o -> hello (链接) 一.静态链接 主要是将符号对应起来 两个主要任务:符号解析(符号引用与符号定义的对应).重定位(符号定义与内存位置的对应) 1. ...

  10. 20155316 2016-2017-2 《Java程序设计》第2周学习总结

    教材学习内容总结 学习主要内容:基本类型介绍及流程控制简介 关键点:关键记住JAVA的大体框架,可以类比C语言结合着记.相较于C不同且值得关注的主要信息有: 基本类型的不同:byte.boolean. ...