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 are 3: 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.

———————————————————————————————————

题目的意思是给出n个区间初始为0每个区间+1,对每次查询问每段区间数大于看的数量

思路:对操作区间每个数++肯定TLE,所以我可以开一个数组b[i]表示i到最后都加1

那么区间[l,r]+1就可以表示为b[l]++,b[r+1]--; 先记录所有操作,在同一处理

查询前搞波前缀和就好了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath> using namespace std; #define LL long long
const int inf=0x7fffffff; int a[200005];
int b[200005];
int pre[200005]; int main()
{
int n,m,k,l,r;
memset(a,0,sizeof a);
memset(pre,0,sizeof pre);
memset(b,0,sizeof b);
scanf("%d%d%d",&n,&k,&m);
for(int i=0;i<n;i++)
{
scanf("%d%d",&l,&r);
a[l]++;
a[r+1]--;
}
for(int i=1;i<200002;i++)
{
b[i]=b[i-1]+a[i];
pre[i]=pre[i-1];
if(b[i]>=k)
pre[i]++;
}
for(int i=0;i<m;i++)
{
scanf("%d%d",&l,&r);
printf("%d\n",pre[r]-pre[l-1]); } return 0;
}

Codeforces816B Karen and Coffee 2017-06-27 15:18 39人阅读 评论(0) 收藏的更多相关文章

  1. Codeforces821B Okabe and Banana Trees 2017-06-28 15:18 25人阅读 评论(0) 收藏

    B. Okabe and Banana Trees time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  2. Hadoop常见异常及其解决方案 分类: A1_HADOOP 2014-07-09 15:02 4187人阅读 评论(0) 收藏

    1.Shell$ExitCodeException 现象:运行hadoop job时出现如下异常: 14/07/09 14:42:50 INFO mapreduce.Job: Task Id : at ...

  3. Codeforces816A Karen and Morning 2017-06-27 15:11 43人阅读 评论(0) 收藏

    A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...

  4. codeforces815A Karen and Game 2017-06-27 15:22 31人阅读 评论(0) 收藏

    C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...

  5. PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏

    Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  6. 安装hadoop1.2.1集群环境 分类: A1_HADOOP 2014-08-29 15:49 1444人阅读 评论(0) 收藏

    一.规划 (一)硬件资源 10.171.29.191 master 10.173.54.84  slave1 10.171.114.223 slave2 (二)基本资料 用户:  jediael 目录 ...

  7. Basic 分类: POJ 2015-08-03 15:49 3人阅读 评论(0) 收藏

    Basic Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 905 Accepted: 228 Description The p ...

  8. Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏

    Gold Coins Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21767   Accepted: 13641 Desc ...

  9. 苹果应用商店AppStore审核中文指南 分类: ios相关 app相关 2015-07-27 15:33 84人阅读 评论(0) 收藏

    目录 1. 条款与条件 2. 功能 3. 元数据.评级与排名 4. 位置 5. 推送通知 6. 游戏中心 7. 广告 8. 商标与商业外观 9. 媒体内容 10. 用户界面 11. 购买与货币 12. ...

随机推荐

  1. Oracle_高级功能(1) 数据库设计

    1.三范式规范化关系模式称为范式.第一范式:在一个关系模型R中,如果R的每一个属性的值域中的值都是不可再分的最小数据单位, 则称R为第一范式(1NF).第二范式:如果一个关系模型R属于1NF,并且R的 ...

  2. istream_iterator和ostream_iterator

    总结: istream_iterator<T>in(strm);T指明此istream_iterator的输入类型,strm为istream_iterator指向的流 提供了输入操作符(& ...

  3. hdu 1254(两个BFS) 推箱子

    http://acm.hdu.edu.cn/showproblem.php?pid=1254 首先,要判断人是不是可以从4到达箱子的位置2,而且不止判断一次,因为推动箱子一步后,人的位置也会改变,所以 ...

  4. Python.SQLAlchemy.0

    1. SQLAlchemy and You http://lucumr.pocoo.org/2011/7/19/sqlachemy-and-you/ 2. Overview http://docs.s ...

  5. Luogu 1273 有线电视网 - 树形背包

    Description 树形背包, 遍历到一个节点, 枚举它的每个子节点要选择多少个用户进行转移. Code #include<cstring> #include<cstdio> ...

  6. JianShu_failban2实现动态屏蔽的功能

    一,首先是服务安装 #vim /etc/yum.repos.d/Centos-Base.repo 在最新新增 [atrpms] name=Red Hat Enterprise Linux $relea ...

  7. swift 属性值变化

    如果创建了一个结构体的实例并将其赋值给一个常量,则无法修改该实例的任何属性,即使有属性被声明为变量也不行. 这种行为是由于结构体(struct)属于值类型.当值类型的实例被声明为常量的时候,它的所有属 ...

  8. requestAnimationFrame 完美兼容封装

    完美兼容封装: (function() { var lastTime = 0; var vendors = ['webkit', 'moz']; for(var x = 0; x < vendo ...

  9. 使用Simple MvvmToolkit开发Android和iOS程序

    详情见:Android and iOS Development with Simple MVVM Toolkit? Yes you can! :http://blog.tonysneed.com/20 ...

  10. C# 单例模式的五种写法

    1.简单实现           C#   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 public sealed c ...