CF816B-Karen and Coffee
来源:互联网 发布:一元秒杀包邮 淘宝 编辑:程序博客网 时间:2024/06/05 00:52
B. Karen and Coffee
time 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?
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.
Examples
input
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100
output
3
3
0
4
input
2 1 1
1 1
200000 200000
90 100
output
0
题目大意:给出n个配料区间,q个查询区间,问每次查询时,该查询区间内有多少个点至少被k个配料区间覆盖。
解题思路: 若给出配料区间[L,R],则cnt[L]++,cnt[R+1]–,然后从左往右扫一遍,用个计数器记录值,维护前缀和,最后结果就是s[b]-s[a-1]
#include<iostream>#include<string>#include<map>#include<set>#include<algorithm>#include<cstdio>#include<cmath>#include<vector>#include<cstring>#include<iomanip>#include<sstream>using namespace std;const int INF=0x3f3f3f3f;const int MAXN=200005;int cnt[MAXN];int s[MAXN];int L,R;int a,b;int n,k,q;int main(){ while(cin>>n>>k>>q) { for(int i=0;i<MAXN;i++) cnt[i]=0; for(int i=1;i<=n;i++) { cin>>L>>R; cnt[L]++; cnt[R+1]--; } for(int i=0;i<MAXN;i++) s[i]=0; int num=0; for(int i=1;i<MAXN;i++) { num+=cnt[i]; if(num>=k) s[i]=s[i-1]+1; else s[i]=s[i-1]; } for(int i=1;i<=q;i++) { cin>>a>>b; cout<<s[b]-s[a-1]<<endl; } } return 0;}
- CF816B-Karen and Coffee
- CF816B-Karen and Coffee
- 前缀和--cf816b karen and coffee
- Karen and Coffee codeforces
- Codeforces816B Karen and Coffee
- Karen and Coffee
- CF419 div2B. Karen and Coffee
- Codeforces#419 Karen and Coffee
- CodeForces B. Karen and Coffee
- Karen and Coffee 816B
- CodeForce Round #479 B. Karen and Coffee
- Karen and Coffee codeforces 816B
- cf#419 Karen and Coffee 前缀和
- Codeforces 816 -B. Karen and Coffee
- Codeforces 816B-Karen and Coffee
- Codeforces 816B Karen and Coffee
- Karen and Coffee(前缀和,大量查询)
- codeforces Karen and Coffee (区间贡献 思维)
- A Story of HealthyAt100--The 12th MiniStory of AJ
- PAT程序设计考题——甲级1068 (背包问题) C++实现
- java编程规范,抽象,继承,封装
- 软件工程(C编码实践篇)学习总结
- 测试 asp.net core 发布
- CF816B-Karen and Coffee
- lnmp配置php环境用到的设置
- 三种基础排序算法及其拓展应用
- Identify Smith Numbers
- 华为P6安装Sygic
- 【51Nod 1789】跑的比谁都快
- 多线程中线程停止的问题
- Java中常用的设计模式
- USACO-Section1.5 SuperPrime Rib [质数]