using
System;
using
System.Collections.Generic;
using
System.Linq;
public
class
GFG {
static
void
Count(
int
n, List<List<
int
> > arr,
List<
int
> query)
{
List<Tuple<
int
,
int
> > vp
=
new
List<Tuple<
int
,
int
> >();
for
(
int
i = 0; i < arr.Count; i++) {
vp.Add(
new
Tuple<
int
,
int
>(arr[i][1], arr[i][0]));
}
List<Tuple<
int
,
int
> > vq
=
new
List<Tuple<
int
,
int
> >();
int
q = query.Count;
for
(
int
i = 0; i < q; i++) {
vq.Add(
new
Tuple<
int
,
int
>(query[i], i));
}
vp.Sort();
vq.Sort();
Dictionary<
int
,
int
> freq
=
new
Dictionary<
int
,
int
>();
List<
int
> ans =
new
List<
int
>(
new
int
[q]);
int
l = 0, r = 0;
for
(
int
i = 0; i < q; i++) {
int
queryNumber = vq[i].Item2;
int
start = vq[i].Item1 / 2;
int
end = vq[i].Item1;
while
(r < vp.Count && vp[r].Item1 <= end) {
if
(!freq.ContainsKey(vp[r].Item2)) {
freq[vp[r].Item2] = 0;
}
freq[vp[r].Item2]++;
r++;
}
while
(l < vp.Count && vp[l].Item1 < start) {
freq[vp[l].Item2]--;
if
(freq[vp[l].Item2] == 0) {
freq.Remove(vp[l].Item2);
}
l++;
}
ans[queryNumber] = n - freq.Count;
}
Console.WriteLine(
string
.Join(
" "
, ans));
}
static
void
Main()
{
int
N = 3;
List<List<
int
> > arr =
new
List<List<
int
> >{
new
List<
int
>{ 1, 4 },
new
List<
int
>{ 2, 1 },
new
List<
int
>{ 1, 1 },
new
List<
int
>{ 3, 2 }
};
List<
int
> query =
new
List<
int
>{ 4, 2 };
Count(N, arr, query);
}
}