CF-816B
B. Karen and Coffeetime limit per test2.5 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard 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?
InputThe 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.
OutputFor each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
Examplesinput3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100output3
3
0
4input2 1 1
1 1
200000 200000
90 100output0NoteIn 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.
题意:
求所给的q个区间中有多少数字在n个区间中出现过不少于k次。
对于每一个区间求前缀和,再讲多余k次的求和。
AC代码:
#include<bits/stdc++.h>
using namespace std; const int MAXN=; int a[MAXN]; int main(){
ios::sync_with_stdio(false);
int n,k,q;
int l,r;
cin>>n>>k>>q;
memset(a,,sizeof(a));
for(int i=;i<=n;i++){
cin>>l>>r;
a[l]++;
a[r+]--;
}
for(int i=;i<MAXN;i++){
a[i]+=a[i-];
}
for(int i=;i<MAXN;i++){
if(a[i]>=k){
a[i]=;
}
else{
a[i]=;
}
}
for(int i=;i<MAXN;i++){
a[i]+=a[i-];
}
int x,y;
for(int i=;i<q;i++){
cin>>x>>y;
cout<<a[y]-a[x-]<<endl;
}
return ;
}
CF-816B的更多相关文章
- Karen and Coffee CF 816B(前缀和)
Description To stay woke and attentive(专注的) during classes, Karen needs some coffee! Karen, a coffee ...
- CF 816B Karen and Coffee【前缀和/差分】
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
随机推荐
- C#连接Oracle的问题(不安装客户端)
win7环境,本地没有安装oracle或者客户端,现在需要程序里连接远程oracle DB: 如果采用System.Data.OracleClient肯定是不行的,这个要安装客户端的: 所以就尝试O ...
- HTML5,不仅仅是看上去非常美(第二弹:打造最美3D机房)
前言 近期项目开发任务告一段落,刚好有时间整理这大半年的一些成果.使用html5时间还不久,对js的认识还不够深入.没办法,曾经一直搞java,对js的一些语言特性和概念一时还转换只是来. 上一篇第一 ...
- 关于Android6.0 之EasyPermissionUtil
之前6.0权限用第三方类库比较多,但是都是挺麻烦的,今天给大家推荐一个好用的第三方类库: gitHub地址:https://github.com/yxping/EasyPermissionUtil 使 ...
- 【BZOJ3924】[Zjoi2015]幻想乡战略游戏 动态树分治
[BZOJ3924][Zjoi2015]幻想乡战略游戏 Description 傲娇少女幽香正在玩一个非常有趣的战略类游戏,本来这个游戏的地图其实还不算太大,幽香还能管得过来,但是不知道为什么现在的网 ...
- Appium 1.9.1 启动报错 Fatal TypeError: Class constructor BaseDriver cannot be invoked without 'new'
安装了appium 1.9.1后一直报错Fatal TypeError: Class constructor BaseDriver cannot be invoked without 'new',无法 ...
- JSON中如何转义字符串中的双引号(转载)
问: I'm trying to show double quotes but it shows one of the backslashes: "maingame": { &qu ...
- [2018-12-07]用ABP入门DDD
前言 ABP框架一直以来都是用DDD(领域驱动设计)作为宣传点之一.但是用过ABP的人都知道,ABP并不是一个严格遵循DDD的开发框架,又或者说,它并没有完整实现DDD的所有概念. 但是反过来说,认真 ...
- Flask中的内置session
Flask中的Session非常的奇怪,他会将你的SessionID存放在客户端的Cookie中,使用起来也非常的奇怪 1. Flask 中 session 是需要 secret_key 的 from ...
- 从动态库的def文件生成lib文件
以sqlite3为例,下载的文件中只有def文件,没有lib文件,想使用静态方式调用dll的情况下,就需要额外的.h文件和.lib文件存在. .h文件可以从官方下载的sqlite-amalgamati ...
- Java多线程系列 基础篇09 Object.wait/notifyJVM源码实现
转载 https://www.jianshu.com/p/f4454164c017 作者 占小狼 最简单的东西,往往包含了最复杂的实现,因为需要为上层的存在提供一个稳定的基础,Object作为java ...
