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#判断WebService接口是否可用
using MSXML2; public bool InterfaceEnble() { string url = "http://localhost:81/WebServiceLogin. ...
- Intellij IDEA创建的Web项目配置Tomcat并启动Maven项目(转)
大部分是直接上图哦. 点击如图所示的地方,进行添加Tomcat配置页面 弹出页面后,按照如图顺序找到,点击+号 tomcat Service -> Local 注意,这里不要选错了哦,还有一个T ...
- 九度OJ 1047:素数判定 (素数)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:9583 解决:4347 题目描述: 给定一个数n,要求判断其是否为素数(0,1,负数都是非素数). 输入: 测试数据有多组,每组输入一个数n ...
- NotePad++ 正则表达式替换
NotePad++ 正则表达式替换 高级用法 [转] - aj117 - 博客园 https://www.cnblogs.com/tibit/p/6387199.html const getQAPar ...
- 【题解】AT2043 AND Grid
[题解]AT2043 AND Grid 我们考虑直接构造两个互补的图切分别联通的图,然后原图有的大家都有就构造完成了. #include<iostream> #include<cst ...
- me12里更改信息记录的净价和有效价格,以及信息记录的条件价格
转自 http://blog.csdn.net/zeewjj/article/details/7941525REPORT ztest. DATA:l_kbetr LIKE konp-kbetr.l_k ...
- 学习 Promise,掌握未来世界 JS 异步编程基础
其实想写 Promise 的使用已经很长时间了.一个是在实际编码的过程中经常用到,一个是确实有时候小伙伴们在使用时也会遇到一些问题.Promise 也确实是 ES6 中 对于写 JS 的方式,有着真正 ...
- JavaScript预解释是一种毫无节操的机制
前言 JavaScript是一门解释型的语言 , 想要运行JavaScript代码需要两个阶段 编译阶段: 编译阶段就是我们常说的JavaScript预解释(预处理)阶段,在这个阶段JavaScrip ...
- JAVA-配置path环境
配置path环境变量变的目的是什么? 控制台可以在任意的路径下都可以找到java的开发工具. 为了说明几个JDK环境变量的作用,这里先给出环境变量的定义 环境变量: 环境变量一般是指在操作系统中用来指 ...
- cmake编译成功之后VS2015可以build Solution但是不可以运行的解决办法
1.在VS2015解决方案管理器中删除掉ALL_BUILD和ZERO_CHECK项,只保留Cmake生成的工程文件. 2.进行第一部之后还是有可能生成(build)失败,此时有可能是缺少文件.
