-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1088 - Points in Segments.cpp
74 lines (70 loc) · 1.31 KB
/
1088 - Points in Segments.cpp
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
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll arr1[100005];
ll bsearch (ll val , ll n)
{
ll low = 0 , high = n;
ll mid;
while(low <= high)
{
mid = (low + high) / 2;
if(arr1[mid] == val)
{
return mid;
}
if(arr1[mid] > val)
{
high = mid - 1;
}
else
low = mid + 1;
}
return low;
}
ll bsearch1 (ll val , ll n)
{
ll low = 0 , high = n;
ll mid;
while(low <= high)
{
mid = (low + high) / 2;
if(arr1[mid] == val)
{
return mid;
}
if(arr1[mid] > val)
{
high = mid - 1;
}
else
low = mid + 1;
}
return high;
}
int main()
{
int tes , o = 0;
///cin >> tes;
scanf("%d", &tes);
while(tes--)
{
ll n , q;
scanf("%lld %lld", &n, &q);
for(int i = 0; i < n; i++)
{
scanf("%lld", &arr1[i]);
}
o++;
printf("Case %d:\n",o);
while(q--)
{
ll l , u;
scanf("%lld %lld", &l ,&u);
ll res1 , res2;
res1= bsearch(l , n - 1);
res2 = bsearch1(u , n - 1);
printf("%lld\n", (res2 - res1) + 1);
}
}
}