Karen and Coffee CF 816B(前缀和)
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, 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.
Sample Input
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
Hint
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.
题目意思:女主为了得到最好的泡咖啡的温度,看了n本书,n本书推荐了n种的适合范围,她想要查询q次,a~b温度范围内有多少个温度是可以允许泡咖啡的时间(这个时间要求至少有k本数推荐过)。
解题思路:当时没有做到这一道题。。。。总的来说这一道题使用前缀和来做,这道题是不是有点像给气球刷颜色的那一类题。
#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(前缀和)的更多相关文章
- Karen and Coffee CodeForces - 816B (差分数组+预处理前缀和)
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- 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 ...
- CF 816B Karen and Coffee【前缀和/差分】
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- CodeForces 816B Karen and Coffee(前缀和,大量查询)
CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the ...
- 816B. Karen and Coffee 前缀和思维 或 线段树
LINK 题意:给出n个[l,r],q个询问a,b,问被包含于[a,b]且这样的区间数大于k个的方案数有多少 思路:预处理所有的区间,对于一个区间我们标记其(左边界)++,(右边界+1)--这样就能通 ...
- codeforces 816B Karen and Coffee (差分思想)
题目链接 816B Karen and Coffee 题目分析 题意:有个人在学泡咖啡,因此看了很多关于泡咖啡温度的书,得到了n种推荐的泡咖啡温度范围[L1,R1] ,此人将有k种做法推荐的温度记为可 ...
- 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 ...
- 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 ...
- CodeForces 816B 前缀和
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
随机推荐
- TCP中的三次握手和四次挥手
三次握手:目的是同步连接双方的序列号和确认号 并交换 TCP窗口大小信息. 理论上跟通话一样: a: 你听的到吗? b: 我能听到.只需要两次就可以了,但建立连接阶段不是双向即时通信的,且最终的目的 ...
- WebGl 缩放(矩阵变换)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 追溯了解Ubuntu之------基本命令操作(叁)
在使用Ubuntu中的一些基本命令与Linux中是有区别的: 1. 查看Ubuntu系统位数:uname -ar 或 getconf LONG_BIT 2. 获取Ubu ...
- linux几个重要的组合键
我们在用Windows系统时,有没有感觉快键键让我们工作更有效率,在Linux系统中仍有很好用的快捷键,这些快捷键可以辅助我们进行指令的编写与程序的中断呢,下面介绍几个经常用到的快捷键. 一.Tab- ...
- python学习之路-基本数据类型1 变量的概念、数字、字符串
1 什么是数据类型? 每种编程语言都有自己的数据类型,用于标识计算机可以认识的数据,Python中主要的数据类型为字符串,整数,浮点数,列表,元祖,字典,集合七种主要的数据类型,其中以列表,字典为最主 ...
- lncRNA芯片重注释
.caret,.dropup>.btn>.caret{border-top-color:#000!important}.label{border:1px solid #000}.table ...
- # C语言假期学习笔记——6
C语言假期学习笔记--6 数组 主要学习了一位数组和二维数组. 数组是一组具有相同类型的变量的集合.C语言程序通过元素的下标来访问数组中的元素.(下标从0开始) 一位数组 类型 数组名[元素个数] 二 ...
- 20155330 实验二 Java面向对象程序设计
20155330 实验二 Java面向对象程序设计 实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验步 ...
- 20145226夏艺华 《Java程序设计》第7&8周学习总结、实验一
[实验一]http://www.cnblogs.com/bestixyh/p/6358734.html [第7周]http://www.cnblogs.com/bestixyh/p/6380475.h ...
- ConfigurationManager 读写AppSettings键值对
using System; using System.Configuration; namespace ConsoleApplication1 { class Program { static voi ...