Karen and Coffee
time limit per test 2 second memory limit per test 256 megabytes
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?

传送门:CF816B

Input

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. 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.

Sample Input

1
2
3
4
5
6
7
8
3 2 4
91 94
92 97
97 99
92 94
93 97
95 96
90 100

Sample Output

1
2
3
4
3
3
0
4

题解

题目意思就是求区间内大于k的个数 查询有200000个 那肯定用前缀和来查询 res[r]-res[l-1] 然后就是线段树的一套区间更新加单点查询维护前缀和了
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.io.*;  
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter pw = new PrintWriter(System.out);
while (sc.hasNext()) {
int n=sc.nextInt();
int k=sc.nextInt();
int q=sc.nextInt();
int[]sum=new int[200050];
int[]res=new int[200050];
SegTree tree=new SegTree(200001);
for(int i=0;i<n;i++){
int a=sc.nextInt();
int b=sc.nextInt();
tree.update(0,a,b+1,1,0, tree.n);
}
//Arrays.sort(node);
for(int i=1;i<=200000;i++){
if(tree.queryreg(0, i, i+1, 0, tree.n)>=k){
res[i]+=(res[i-1]+1);
}else{
res[i]=res[i-1];
}
}
for(int j=0;j<q;j++){
int l=sc.nextInt();
int r=sc.nextInt();
pw.println(res[r]-res[l-1]);
}
pw.flush();
}
}
}
class SegTree{
int[]tree=new int[900050];
int[]lazy=new int[900050];
int n;
SegTree(int n_){
this.n=1;
while(n<n_){
n*=2;
}
Arrays.fill(tree, 0);
}
void pushdown(int num,int l,int r){
if(lazy[num]!=0){
tree[num*2+1]+=lazy[num];
tree[num*2+2]+=lazy[num];
lazy[num*2+1]+=lazy[num];
lazy[num*2+2]+=lazy[num];
lazy[num]=0;
}
}
void update(int num,int l,int r,int add,int x,int y){
if(r<=x||l>=y)return;
if(l<=x&&r>=y){
tree[num]+=add;
lazy[num]+=add;
return;
}
pushdown(num,x,y);
update(num*2+1,l,r,add,x,(x+y)/2);
update(num*2+2,l,r,add,(x+y)/2,y);
tree[num]=tree[num*2+1]+tree[num*2+2];
}
int queryreg(int num,int l,int r,int x,int y){
if(r<=x||l>=y)return 0;
if(l<=x&&r>=y){
return tree[num];
}
pushdown(num,x,y);
int left=queryreg(num*2+1,l,r,x,(x+y)/2);
int right=queryreg(num*2+2,l,r,(x+y)/2,y);
return left+right;
}
}