codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

816B.md (3935B)


      1 Source: https://codeforces.com/problemset/problem/816/B
      2 
      3 B. Karen and Coffee
      4 
      5 time limit per test
      6 
      7 2.5 seconds
      8 
      9 memory limit per test
     10 
     11 512 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 To stay woke and attentive during classes, Karen needs some coffee!
     22 
     23  ![](https://espresso.codeforces.com/d3ec9da91288120e5f9bf542a33dfb52f6abc639.png) 
     24 
     25 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".
     26 
     27 She knows *n* coffee recipes. The *i*-th recipe suggests that coffee should be brewed between *l**i* and *r**i* degrees, inclusive, to achieve the optimal taste.
     28 
     29 Karen thinks that a temperature is admissible if at least *k* recipes recommend it.
     30 
     31 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?
     32 
     33 Input
     34 
     35 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.
     36 
     37 The next *n* lines describe the recipes. Specifically, the *i*-th line among these contains two integers *l**i* and *r**i* (1 ≤ *l**i* ≤ *r**i* ≤ 200000), describing that the *i*-th recipe suggests that the coffee be brewed between *l**i* and *r**i* degrees, inclusive.
     38 
     39 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.
     40 
     41 Output
     42 
     43 For each question, output a single integer on a line by itself, the number of admissible integer temperatures between *a* and *b* degrees, inclusive.
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 3 2 4  
     51 91 94  
     52 92 97  
     53 97 99  
     54 92 94  
     55 93 97  
     56 95 96  
     57 90 100
     58 ```
     59 
     60 Output
     61 
     62 ```
     63 3  
     64 3  
     65 0  
     66 4
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 2 1 1  
     73 1 1  
     74 200000 200000  
     75 90 100
     76 ```
     77 
     78 Output
     79 
     80 ```
     81 0
     82 ```
     83 
     84 Note
     85 
     86 In the first test case, Karen knows 3 recipes.
     87 
     88 1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive.
     89 2. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive.
     90 3. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive.
     91 
     92 A temperature is admissible if at least 2 recipes recommend it.
     93 
     94 She asks 4 questions.
     95 
     96 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.
     97 
     98 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.
     99 
    100 In her third question, she wants to know the number of admissible integer temperatures between 95 and 96 degrees, inclusive. There are none.
    101 
    102 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.
    103 
    104 In the second test case, Karen knows 2 recipes.
    105 
    106 1. The first one, "wikiHow to make Cold Brew Coffee", recommends brewing the coffee at exactly 1 degree.
    107 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.
    108 
    109 A temperature is admissible if at least 1 recipe recommends it.
    110 
    111 In her first and only question, she wants to know the number of admissible integer temperatures that are actually reasonable. There are none.