Codeforces816B Karen and Coffee 2017-06-27 15:18 39人阅读 评论(0) 收藏
2.5 seconds
512 megabytes
standard input
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?
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.
———————————————————————————————————
题目的意思是给出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) 收藏的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 安装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 目录 ...
- Basic 分类: POJ 2015-08-03 15:49 3人阅读 评论(0) 收藏
Basic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 905 Accepted: 228 Description The p ...
- Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏
Gold Coins Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21767 Accepted: 13641 Desc ...
- 苹果应用商店AppStore审核中文指南 分类: ios相关 app相关 2015-07-27 15:33 84人阅读 评论(0) 收藏
目录 1. 条款与条件 2. 功能 3. 元数据.评级与排名 4. 位置 5. 推送通知 6. 游戏中心 7. 广告 8. 商标与商业外观 9. 媒体内容 10. 用户界面 11. 购买与货币 12. ...
随机推荐
- Task 和 ThreadPool
在C#中 TASK 和 ThreadPool 都可以完成多任务并行的工作.但是 TASK实际上是微软定义好的,基于 ThreadPool 的一个类.这里面微软做了很多优化工作. Task Parall ...
- Cookie 和 Session 的区别和联系?session的生命周期?多个服务器部署session的管理?
一.session 和 cookie 1.cookie Cookie会根据响应报文里的一个叫做Set-Cookie的首部字段信息,通知客户端保存Cookie.当下次客户端再向服务端发起请求时,客户端会 ...
- Java.Class
Class类 1. Class继承自Object. 2. .class 和 instance.getClass()的区别 Ref[1] Reference 1. .class http://stack ...
- javascript 高级程序设计 十
理解JS对象(2)创建对象 JS中创建对象的方式有很多,我们把他们统称为模式. 工厂模式: 优点:解决了创建多个相似对象的问题. 缺点:没有解决对象识别问题.(不知道一个实例对象的类型) func ...
- git分支切换时的时间戳问题
1.为什么git仓库没有保留文件修改时的时间戳? 摘自:https://git.wiki.kernel.org/index.php/Git_FAQ#Why_isn.27t_Git_preservin ...
- sqli-labs:18-22,http头部注入
sqli18: uname和passwd被处理了: uagent和ip插入到了数据库: 还带回显. 抓包改包 sqli19: null sqli20: 审计代码,大概如下 当我们正常登录后userna ...
- 【Web】Nginx Rewrite规则
Rewrite介绍 Rewrite主要的功能就是实现URL的重写,Nginx的Rewrite规则采用Pcre,perl兼容正则表达式的语法规则匹配,如果需要Nginx的Rewrite功能,在编译Ngi ...
- spring学习 五 依赖注入的方式
依赖注入有两种方式: 1 构造注入,如果<bean>标签下使用<contructor-arg>,则是构造注入 2 setter注入,就是调用setter方法注入,如果<b ...
- 组合数问题(NOIP2016)
题目链接:组合数问题 这道题可以算当年第二简单的. 这里要用到两个技巧: 用杨辉三角递推计算组合数 运用前缀和 有了这两点,这道题就出来了. 我们先运用杨辉三角推出题目范围内所能用到的所有组合数,然后 ...
- Python之字符串基本操作
#!/usr/bin/env python#-*-coding utf8-*-#Author:caojininfo = { 'stu1001': 'caojin', 'stu1002': 'zhaom ...