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

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.

———————————————————————————————————

题目的意思是给出n个区间初始为0每个区间+1,对每次查询问每段区间数大于看的数量

思路:对操作区间每个数++肯定TLE,所以我可以开一个数组b[i]表示i到最后都加1

那么区间[l,r]+1就可以表示为b[l]++,b[r+1]--; 先记录所有操作,在同一处理

查询前搞波前缀和就好了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath> using namespace std; #define LL long long
const int inf=0x7fffffff; int a[200005];
int b[200005];
int pre[200005]; int main()
{
int n,m,k,l,r;
memset(a,0,sizeof a);
memset(pre,0,sizeof pre);
memset(b,0,sizeof b);
scanf("%d%d%d",&n,&k,&m);
for(int i=0;i<n;i++)
{
scanf("%d%d",&l,&r);
a[l]++;
a[r+1]--;
}
for(int i=1;i<200002;i++)
{
b[i]=b[i-1]+a[i];
pre[i]=pre[i-1];
if(b[i]>=k)
pre[i]++;
}
for(int i=0;i<m;i++)
{
scanf("%d%d",&l,&r);
printf("%d\n",pre[r]-pre[l-1]); } return 0;
}

Codeforces816B Karen and Coffee 2017-06-27 15:18 39人阅读 评论(0) 收藏的更多相关文章

  1. Codeforces821B Okabe and Banana Trees 2017-06-28 15:18 25人阅读 评论(0) 收藏

    B. Okabe and Banana Trees time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. Hadoop常见异常及其解决方案 分类: A1_HADOOP 2014-07-09 15:02 4187人阅读 评论(0) 收藏

    1.Shell$ExitCodeException 现象:运行hadoop job时出现如下异常: 14/07/09 14:42:50 INFO mapreduce.Job: Task Id : at ...

  3. Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏

    A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...

  4. codeforces815A Karen and Game 2017-06-27 15:22 31人阅读 评论(0) 收藏

    C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...

  5. PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏

    Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  6. 安装hadoop1.2.1集群环境 分类: A1_HADOOP 2014-08-29 15:49 1444人阅读 评论(0) 收藏

    一.规划 (一)硬件资源 10.171.29.191 master 10.173.54.84  slave1 10.171.114.223 slave2 (二)基本资料 用户:  jediael 目录 ...

  7. Basic 分类: POJ 2015-08-03 15:49 3人阅读 评论(0) 收藏

    Basic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 905 Accepted: 228 Description The p ...

  8. Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏

    Gold Coins Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21767   Accepted: 13641 Desc ...

  9. 苹果应用商店AppStore审核中文指南 分类: ios相关 app相关 2015-07-27 15:33 84人阅读 评论(0) 收藏

    目录 1. 条款与条件 2. 功能 3. 元数据.评级与排名 4. 位置 5. 推送通知 6. 游戏中心 7. 广告 8. 商标与商业外观 9. 媒体内容 10. 用户界面 11. 购买与货币 12. ...

随机推荐

  1. (转)关于X64位系统IIS7下支持32位asp.net程序

    最近在windows2008 x64位系统下的IIS7下部署asp.net程序. vs2005或vs2008默认的情况下是Any cpu 的也就是支持x86和x64两种系统的.可我的程序在引用了一个三 ...

  2. js 中 的 if使用条件

    在javascript中,哪些值能作为if的条件呢 1.布尔变量true/false2.数字非0,非NaN/ (0 或NaN) 见下面的例子,莫以为负数就以为if语句为假了. 复制代码代码如下: va ...

  3. shell脚本${}、##和%%使用范例

    file=/dir1/dir2/dir3/my.file.txt 可以用${ }分别替换得到不同的值: ${file#*/}:删掉第一个 / 及其左边的字符串:dir1/dir2/dir3/my.fi ...

  4. 定时任务起的java进程没有释放导致oracle的问题not availavle & out of memory

    最近发现一个问题,我们设置了一个定时任务,用于每天的对账,每天的对账都是启动一个java程序(jar包),时间久了,出现下面的问题: 有很多CardPaymentBatch.jar进程驻留在系统当中, ...

  5. iOS常用代码总结

    1.读取图片NSString *path = [[NSBundle mainBundle] pathForResource"icon" ofType"png"] ...

  6. Java中的权限修饰符

    What:访问控制权限是可以设置代码的访问范围. Where:访问权限既可以修饰类中的属性,又可以修饰类中的方法,而public和default还可以修饰类. 在同一个java文件里,公有类有且仅有一 ...

  7. Loadrunner 脚本录制策略

    Loadrunner在脚本录制过程中,我们会先后分别碰见init.action.transaction.end.block等概念.本次打算以图文并茂的形式为大家分别讲解. 以下为一个简要的网站操作逻辑 ...

  8. Spring 中的类加载机制 - ClassLoader

    Spring 中的类加载机制 - ClassLoader Spring 系列目录(https://www.cnblogs.com/binarylei/p/10198698.html) ClassLoa ...

  9. Windows 8 Stroe Apps 控件

    重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter; 容 ...

  10. canvas绘图实现浏览器等待效果

    一:创建画布 <canvas width="600" height="600" id="canvas" style="bor ...