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.

题解:

开一个线段树区间修改输入的东西,然后从1扫到200000 如果该位>=k就把该位赋为1

询问就是区间查询

水题,乱搞即可

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ls (node<<1)
#define rs (node<<1|1)
using namespace std;
const int N=;
int Tree[][N*],mark[][N*];
void updata(bool t,int node){
Tree[t][node]=Tree[t][ls]+Tree[t][rs];
}
void pushdown(bool t,int node)
{
int k=mark[t][node];
mark[t][ls]+=k;mark[t][rs]+=k;
Tree[t][ls]+=k;Tree[t][rs]+=k;
mark[t][node]=;
}
void add(bool t,int l,int r,int node,int sa,int se)
{
if(l>se || r<sa)return ;
if(sa<=l && r<=se)
{
Tree[t][node]++;
mark[t][node]++;
return ;
}
pushdown(t,node);
int mid=(l+r)>>;
add(t,l,mid,ls,sa,se);
add(t,mid+,r,rs,sa,se);
updata(t,node);
}
int getsum(bool t,int l,int r,int node,int sa,int se)
{
if(l>se || r<sa)return ;
if(sa<=l && r<=se)return Tree[t][node];
int mid=(l+r)>>;
pushdown(t,node);
updata(t,node);
return getsum(t,l,mid,ls,sa,se)+getsum(t,mid+,r,rs,sa,se);
}
int main()
{
int n,m,q,x,y,tmp;
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++)
{
scanf("%d%d",&x,&y);
add(,,,,x,y);
}
for(int i=;i<=;i++)
{
tmp=getsum(,,,,i,i);
if(tmp>=m)add(,,,,i,i);
}
for(int i=;i<=q;i++)
{
scanf("%d%d",&x,&y);
printf("%d\n",getsum(,,,,x,y));
}
return ;
}

codeforces round #419 B. Karen and Coffee的更多相关文章

  1. Codeforces Round #419 D. Karen and Test

    Karen has just arrived at school, and she has a math test today! The test is about basic addition an ...

  2. codeforces round #419 E. Karen and Supermarket

    On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a ...

  3. codeforces round #419 C. Karen and Game

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

  4. codeforces round #419 A. Karen and Morning

    Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As yo ...

  5. Codeforces Round #419 (Div. 2) B. Karen and Coffee(经典前缀和)

    http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs s ...

  6. Codeforces Round #419 (Div. 2) B. Karen and Coffee

    To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, want ...

  7. Codeforces Round #419 (Div. 2)

    1.题目A:Karen and Morning 题意: 给出hh:mm格式的时间,问至少经过多少分钟后,该时刻为回文字符串? 思路: 简单模拟,从当前时刻开始,如果hh的回文rh等于mm则停止累计.否 ...

  8. Codeforces Round #419 A+B

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

  9. Codeforces Round #419 (Div. 2) A B C 暴力 区间更新技巧 +前缀和 模拟

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

随机推荐

  1. 敏捷冲刺每日报告——Day1

    1.情况简述 Alpha阶段第一次Scrum Meeting 敏捷开发起止时间 2017.10.25 00:00 -- 2017.10.26 00:00 讨论时间地点 2017.10.25晚9:30, ...

  2. 每日冲刺报告——Day1(Java-Team)

    第一天报告(11.2  周四) 团队:Java-Team 成员: 章辉宇(284) 吴政楠(286) 陈阳(PM:288) 韩华颂(142) 胡志权(143) github地址:https://git ...

  3. 2018上c语言第0次作业

    随笔: 1.翻阅邹欣老师博客关于师生关系博客,并回答下列问题,每个问题的答案不少于500字: (1)最理想的师生关系是健身教练和学员的关系,在这种师生关系中你期望获得来自老师的哪些帮助? 答:对此问题 ...

  4. JAVA使用和操作properties文件

    java中的properties文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,格式为文本文件,文件的内容是格式是"键=值"的格式,在properti ...

  5. 20145237 《Java程序设计》第三周学习总结

    20145237 <Java程序设计>第3周学习总结 教材学习内容总结 第四章主要讲了Java基本类型中的类类型,如何定义类.构造函数.使用标准类.基本类型打包器.数组复制.字符串等内容查 ...

  6. 【转】Python处理wave文件

    #本文PDF版下载 Python解析Wav文件并绘制波形的方法 #本文代码下载 Wav波形绘图代码 #本文实例音频文件night.wav下载 音频文件下载 (石进-夜的钢琴曲) 前言 在现在繁忙的生活 ...

  7. 自定义SpringBoot启动banner

    序: springboot启动的时候会有一个启动logo似的东西,如图,这个logo似的东西叫做banner,本文小计修改此banner显示与关闭banner.没什么用,有兴趣可以玩玩-- 正文: 自 ...

  8. 大数据学习总结(4)参考splunk架构

  9. 启动Eclipse时An internal error occurred during: "Initializing Java Tooling".错误

    解决方法一 重置窗口布局: windows > perspective > reset perspective 解决方法二: 如果上述方法不好使,采用下面的这种方法: 删除workspac ...

  10. C++ 排列最优解算法思想

    枚举全排列 #include <iostream> #include <cstring> #include <string> using namespace std ...