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. ...
随机推荐
- Eclipse的下载及安装
Eclipse的下载地址: https://www.eclipse.org/downloads/ 下载完成后,双击安装包即可安装 选择 Eclipse IDE for Java EE Decelope ...
- [SoapUI] 从上一个测试步骤获取ID list,通过Groovy脚本动态生成 Data Source 供后面的步骤使用
https://support.smartbear.com/readyapi/docs/testing/data-driven/types/groovy.html 从官网拷贝code到SoapUI里面 ...
- Python之路(第十一篇)装饰器
一.什么是装饰器? 装饰器他人的器具,本身可以是任意可调用对象,被装饰者也可以是任意可调用对象. 强调装饰器的原则:1 不修改被装饰对象的源代码 2 不修改被装饰对象的调用方式 装饰器的目标:在遵循1 ...
- sqli盲注自用脚本
盲注脚本 # -*- coding:utf-8 -*- import requests import re url = "http://123.206.87.240:8002/chengji ...
- SpringBoot定制修改Servlet容器
1.如何修改Servlet容器的相关配置: 第一种:在application.properties中修改和server有关的配置(ServerProperties提供): server.port=80 ...
- 使用promise判断是否登录
步骤: 1.创建并返回new Promise((success,error)=>{}),success和error分别是成功和失败后所执行的函数 2.判断是否含有cookie,如果含有cooki ...
- 解决设置select默认选中不生效的方法
$scope.storageTypeList = ['Glusterfs','NFS','Ceph']; 不生效的方法: <select class="form-control&quo ...
- php Amome框架 层次设计备注
层次说明: 每一级中函数都是为而且只为 上(高)一层 的文件服务的 最底层: AmemoMySql 基础数据库函数:AmemoConfig 数据库信息配置文件 再高一层: 一个文件对应一个 ...
- Mybatis-Plus 实战完整学习笔记(五)------insert测试
一.更新操作探究(3.0.3版本) demo /** * 修改用户 * @throws SQLException */ @Test public void update() throws SQLExc ...
- MacOS使用常用配置
如何增加tree命令? 安装Homebrew步骤:http://blog.csdn.net/xianyiqi/article/details/51297562 安装npm步骤:https://blog ...