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. 关于使用栈将一般运算式翻译为后缀表达式并实现三级运算的方法及实例(cpp版)

    #include <iostream> #include <stack> #include <vector> #include <string> #de ...

  2. Ubuntu下tomcat或eclipse启动提示没有java环境问题

    tomcat和eclipse默认使用了openjdk,通过压缩包安装的jdk无法被识别,通过修改tomcat/bin下的catalina.sh添加jdk和jre路径即可 sudo gedit cata ...

  3. python pdb 调试

    命令行 Python -m pdb xxx.py l ----> list 显示当前代码 n ----> next 向下执行一行代码 c ----> continue 继续执行代码 ...

  4. 修改MYSQL的默认连接时长

    show global variables like 'wait_timeout'; 设置成10小时; set global wait_timeout=36000;

  5. maven(二)创建工程

    创建动态Web工程打war包 ​ File→new→Maven Project→勾上create a simple project→然后next> ​ 然后会报一下的错 ​ 解决 ​ 创建jav ...

  6. 使用IDEA快速插入数据库数据的方法

    如上图所示:数据库创建表主键使用了自增列自增因此忽略,只有后两列非主键得数据,在数据较多得时候使用IDEA快捷键Ctrl+R键,快速查找替换.

  7. 算法题丨Move Zeroes

    描述 Given an array nums, write a function to move all 0's to the end of it while maintaining the rela ...

  8. 操作MP3文件的元数据

    参见:http://jingyan.baidu.com/article/03b2f78c4d5eae5ea237aee7.html 一.MP3文件的元数据 一个规则的MP3文件大致含有3个部分: TA ...

  9. Docker学习笔记 - Docker客户端和服务端

    学习内容: Docker客户端和服务端的通讯方式:client和自定义程序 Docker客户端和服务端的连接方式:socket 演示Docker客户端和服务端之间用remote-api通讯:nc   ...

  10. Spark入门(1-3)Spark的重要概念

    1.什么是弹性分布式数据集? Spark提出了RDD(Resilient Distributed Datasets)这么一个全新的概念,RDD弹性分布式数据集是并行.容错的分布式数据结构:可以将RDD ...