Codeforces Round #419 (Div. 2) B. Karen and Coffee
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?
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.
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
3
3
0
4
2 1 1
1 1
200000 200000
90 100
0
In the first test case, Karen knows 3 recipes.
- The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.
 - The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.
 - 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.
- The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.
 - 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.
解题思路:
题目很简单,没啥讲的,暴力会超时,要用前缀和处理。。。但没看过这个算法,正好看到延迟标记,所以用延迟标记的思想,将变化量先用标记下来,最后在一个循环处理.
实现代码:
#include<iostream>
using namespace std;
int a,b,sum[],flag[],c[];
int main()
{
int n,k,q,q1,q2,i,j;
cin>>n>>k>>q;
for(i=;i<=n;i++){
cin>>a>>b;
c[a]++;
c[b+]--;
}
int num = ;
int num1 = ;
for(i=;i<=;i++){
num1+=c[i];
flag[i]=num1;
}
for(i=;i<=;i++){
if(flag[i]>=k)
num++;
sum[i] = num;
}
for(i=;i<q;i++){
cin>>q1>>q2;
if(flag[q1]>=k)
cout<<sum[q2] - sum[q1]+<<endl;
else
cout<<sum[q2] - sum[q1]<<endl;
}
return ;
}
Codeforces Round #419 (Div. 2) B. Karen and Coffee的更多相关文章
- 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 ...
 - Codeforces Round #419 (Div. 2) C. Karen and Game
		
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
 - Codeforces Round #419 (Div. 2) E. Karen and Supermarket(树形dp)
		
http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路 ...
 - Codeforces Round #419 (Div. 2) A. Karen and Morning(模拟)
		
http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟, ...
 - Codeforces Round #419 (Div. 1) C. Karen and Supermarket 树形DP
		
C. Karen and Supermarket On the way home, Karen decided to stop by the supermarket to buy some g ...
 - 【找规律】【递推】【二项式定理】Codeforces Round #419 (Div. 1) B. Karen and Test
		
打个表出来看看,其实很明显. 推荐打这俩组 11 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 1000000000 ...
 - 【贪心】 Codeforces Round #419 (Div. 1) A. Karen and Game
		
容易发现,删除的顺序不影响答案. 所以可以随便删. 如果行数大于列数,就先删列:否则先删行. #include<cstdio> #include<algorithm> usin ...
 - Codeforces Round #419 (Div. 2)
		
1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否 ...
 - Codeforces Round #419 (Div. 2) A B C 暴力 区间更新技巧 +前缀和 模拟
		
A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...
 
随机推荐
- grep配置颜色显示
			
查日志时候必须要用的命令,为了在终端方便显示查看,可以加颜色和高亮等设置. 自己习惯用的: GREP_COLOR='a;b' a=4表示下划线,b=41表示红色背景高亮 在~/.bashrc文件中加 ...
 - linux编程头文件所在路径的问题
			
一.问题引入 1.头文件与库 当我们在PC主机linux环境下(如ubuntu),编写linux应用程序,然后利用gcc来编译.在源代码的开始位置会写入头文件,那是因为我们使用了系统提供的库函数,例如 ...
 - LOJ #559. 「LibreOJ Round #9」ZQC 的迷宫
			
一道ZZ结论题,主要是来写一写交互题的. 我们要先知道一句话: 扶着墙是肯定可以走出简单迷宫的. 然后我们冷静分析问题.若这个迷宫是\(n\times m\)的,那么最多有\(2mn+n+m\)个墙壁 ...
 - 面试4——java进程和线程相关知识
			
1.线程和进程的概念.并行和并发的概念
 - 利用matplotlib的plot函数实现图像绘制
			
模式识别的一个实验,要求画出贝叶斯决策的图.这里我是利用python中的matplotlib库实现的图线的拟合.主要对于matplotlib的使用可以参照博客:webary 如果要绘制三维图像可以参考 ...
 - 一文让你熟练掌握Linux的ncat(nc)命令
			
一文让你熟练掌握Linux的ncat(nc)命令 ncat 或者说 nc 是一款功能类似 cat 的工具,但是是用于网络的.它是一款拥有多种功能的 CLI 工具,可以用来在网络上读.写以及重定向数据. ...
 - python之requests
			
发送请求 导入 Requests 模块: >>> import requests >>> r = requests.get('https://xxxxxxx.jso ...
 - 结构体内嵌比较函数bool operator < (const node &x) const {}
			
直接看别人的链接 [http://www.cnblogs.com/ZERO-/p/9347296.html]
 - Beta项目展示
			
Team C# 一.团队成员简介 杜正远,队长. 博客地址:http://www.cnblogs.com/kevindu/ 崔强,全职PM. 博客地址:http://www.cnblogs.com/m ...
 - Linux内核分析作业五
			
扒开系统调用的三层皮(下) 给MenuOS增加time和time-asm命令 步骤 rm menu -rf //强制删除 git clone http://github.com/menging/men ...