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 ...
随机推荐
- 如何发布自己模块到NPM
创建项目 npm init name: (my-npm) version: (1.0.0) description: 0.0.1 entry point: (index.js) test comman ...
- Redis笔记 -- 链表和链表节点的API函数(三)
链表和链表节点API 函数 作用 时间复杂度 listSetDupMethod 将给定的函数设置为链表的节点值复制函数 复制函数可以通过链表的dup属性直接获得,O(1) listGetDupMeth ...
- PHP程序员的技术成长规划 第二阶段:提高阶段
第二阶段:提高阶段 (中级PHP程序员) 重点:提高针对LNMP的技能,能够更全面的对LNMP有熟练的应用.目标:能够随时随地搭建好LNMP环境,快速完成常规配置:能够追查解决大部分遇到的开发和线上环 ...
- STM32 Startup**.s文件中使用的 __main C函数入口
代码: ; Reset handler Reset_Handler PROC EXPORT Reset_Handler [WEAK] IMPORT SystemInit IMPORT __main L ...
- Python学习——编程语言介绍
开发语言 高级语言:基于C/汇编等封装的语言,如Python.Java.C#.PHP.Go.ruby.C++……生成字节码让C/汇编去识别 低级语言:直接让计算机底层能识别成机器码的语言(计算机再将机 ...
- zabbix-3.2.3安装
环境:lapp 操作系统: rhel7.0apache: apache-2.4数据库: postgresql-9.2.10php: php-5.4.16-21zabbix: zabbix-3.2.3 ...
- 版本控制工具(下)——Git的远程仓库、分支管理与其它操作
预备知识: SSH协议参考资料:http://blog.csdn.net/vevenlcf/article/details/43273405 图解公钥和私钥:http://blog.csdn.net/ ...
- 20155306 《信息安全技术概论》实验二 Windows口令破解
20155306 <信息安全技术概论>实验二 Windows口令破解 [实验目的] 了解Windows口令破解原理 对信息安全有直观感性认识 能够运用工具实现口令破解 [实验人数] 每组1 ...
- 20145226夏艺华 网络对抗技术EXP4 恶意代码分析
20145226夏艺华 网络对抗技术EXP4 恶意代码分析(未完成版) 回答问题 (1)如果在工作中怀疑一台主机上有恶意代码,但只是猜想,所有想监控下系统一天天的到底在干些什么.请设计下你想监控的操作 ...
- OpenCV参考手册之Mat类详解
OpenCV参考手册之Mat类详解(一) OpenCV参考手册之Mat类详解(二) OpenCV参考手册之Mat类详解(三)