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;}
阅读全文
0 0
原创粉丝点击