Codeforces Round #419 (Div. 2)Karen and Coffee
来源:互联网 发布:淘宝优惠券大小尺寸 编辑:程序博客网 时间:2024/06/05 04:03
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
#include <iostream>#include <iomanip>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <string>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#define mem(a) memset(a, 0, sizeof(a))using namespace std;typedef pair<int, int> Pii;typedef long long LL;const int MAXN = 200005;const int inf = 0x3f3f3f3f;const int Mod = 100000000;int vis[MAXN];int a[MAXN];struct node{ int l, r;};int main(){ int n, k, q, l, r; while(~scanf("%d %d %d", &n, &k, &q)) { memset(vis, 0, sizeof(vis)); memset(a, 0, sizeof(a)); for(int i=1;i<=n;++i) { scanf("%d %d", &l, &r); vis[l]++, vis[r+1]--; } for(int i=1;i<=200000;++i) { vis[i]+=vis[i-1]; } for(int i=1;i<=200000;++i) { if(vis[i]>=k) vis[i]=1; else vis[i]=0; } for(int i=2;i<=200000;++i) { vis[i]+=vis[i-1]; } while(q--) { scanf("%d %d", &l, &r); printf("%d\n", vis[r]-vis[l-1]); } } return 0;}
- Codeforces Round #419 (Div. 2)Karen and Coffee
- Codeforces Round #419 (Div. 2)Karen and Coffee
- Codeforces Round #419 (Div. 2) B. Karen and Coffee
- Codeforces Round #419 (Div. 2) B. Karen and Coffee (差分标记)
- Codeforces Round #419 (Div. 2) B. Karen and Coffee 预处理+技巧
- [前缀和] Codeforces Round #419 (Div. 2)B. Karen and Coffee
- Codeforces Round #419 (Div. 2) B. Karen and Coffee【前缀和求区间覆盖次数】
- Codeforces#419 Karen and Coffee
- Karen and Coffee codeforces
- CodeForces #419 Div.2 B Karen and Coffee 差分 巧妙
- Codeforces Round #419 (Div. 2) C.Karen and Game 思维
- Codeforces Round #419 (Div. 2)Karen and Game
- Codeforces Round #419 (Div. 2) C. Karen and Game 题解
- Codeforces Round #419 (Div. 2) A. Karen and Morning
- Codeforces Round #419 (Div. 2) C. Karen and Game【贪心】
- Codeforces Round #419 (Div. 2)_Karen and Coffee
- CodeForces B. Karen and Coffee
- Codeforces Round #419 (Div. 2) (Codeforces 815B) D. Karen and Test 组合数学
- [leetcode]315. Count of Smaller Numbers After Self
- 【支付系统学习笔记】 一支付概述(1支付与交易)
- 2017中国程序员薪资生存现状调查报告
- Spring 4初识aop
- JDBC
- Codeforces Round #419 (Div. 2)Karen and Coffee
- mysql必知必会
- echarts-特殊需求
- 添加OpenSSL库支持for WPA on RTEMS-libbsd
- HTML:Advanced Web Construction
- Android进阶系列之2:HandlerThread详解
- 数据库范式、事务、锁学习
- 如何避免ASP.NET缓存占用资源?
- 竞赛 电子设计大赛 四轴无人机 建议