zoukankan      html  css  js  c++  java
  • B. Karen and Coffee(Round419)

    B. Karen and Coffee
    time limit per test
    2.5 seconds
    memory limit per test
    512 megabytes
    input
    standard input
    output
    standard 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, nk (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
    Note

    In the first test case, Karen knows 3 recipes.

    1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.
    2. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.
    3. 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 are3: 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.

    1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.
    2. 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.

     hint:给你n个区间,满足数x,m个询问。。。。

    在每个询问中,给出该询问区间中有多少个点在给定的区间中满足x个区间的覆盖

    这是一个前缀和的问题(新知识技能get):输入一个区间 l, r之后,我们用一个数组记录a来预记录,执行操作a[l]++, a[r+1]--

    在所有的区间输入完成之后,我们用从前往后扫描a[i],求出每一个i出现的次数

    最后用一个sum数组来记录0 - i之间满足条件的点的个数。。。

    所以对于任意一个询问区间 L R来说,满足条件的个数为sum[R+1]-sum[L]

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<string.h>
     4 using namespace std;
     5 //一些常用的表达式缩写形式!!!
     6 #define mem(a, b) memset(a, b, sizeof(a))
     7 #define FOR(i, a, b) for(int i=a; i<b; i++)
     8 #define FO(i, a, b) for(int i=a; i<=b; i++)
     9 const int maxn = 200500;
    10 int vis[maxn], sum[maxn];
    11 
    12 //前缀和思想!!!
    13 int main(){
    14     int n, k, q, i, j;
    15     scanf("%d %d %d", &n, &k, &q);
    16     FOR(i, 0, n){
    17         int l, r;
    18         scanf("%d%d", &l, &r);
    19         vis[l]++;
    20         vis[r+1]--;
    21     }
    22     FO(i, 1, maxn){
    23         vis[i]+=vis[i-1];
    24         if(vis[i]>=k) ++sum[i];
    25     }
    26     FOR(i, 1, maxn){
    27         sum[i]+=sum[i-1];
    28     }
    29     FOR(i, 0, q){
    30         int l, r;
    31         scanf("%d%d", &l, &r);
    32         printf("%d
    ", sum[r]-sum[l-1]);
    33     }
    34     return 0;
    35 }
  • 相关阅读:
    《人月神话》读后感-何保委
    软件工程2017第二次作业随笔-何保委
    软件工程2017第一次作业随笔
    实验吧 REVERSE
    浙大ctf REVERSE
    eclipse安装
    表单
    【南京邮电】maze 迷宫解法
    看雪.TSRC 2017CTF秋季赛第三题
    使用Z3破解简单的XOR加密
  • 原文地址:https://www.cnblogs.com/ledoc/p/7126845.html
Copyright © 2011-2022 走看看