-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLOJ1088.cpp
More file actions
54 lines (43 loc) · 1.01 KB
/
LOJ1088.cpp
File metadata and controls
54 lines (43 loc) · 1.01 KB
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
#include <bits/stdc++.h>
using namespace std;
int n,m,t;
int main() {
//freopen("input.txt","r",stdin);
cin>>t;
for(int j=1; j<=t; j++){
cin>>n>>m;
int arr[n];
for(int i=1; i<=n; i++){
cin>>arr[i];
}
sort(arr+1,arr+n+1);
cout<<"Case "<<j<<":"<<endl;
while(m--){
int lLimit,hLimit;
cin>>lLimit>>hLimit;
int low = 1;
int high = n;
while(high-low>1){
int mid = (low+high)/2;
if(arr[mid]<lLimit) low = mid+1;
else high = mid;
}
if(arr[low]>=lLimit) lLimit = low;
else if(arr[high]>=lLimit) lLimit = high;
else lLimit = -1;
if(lLimit<0) cout<<0<<endl;
else{
low = 1;
high = n;
while(high-low>1){
int mid = (low+high)/2;
if(arr[mid]<=hLimit) low = mid+1;
else high = mid;
}
if(arr[low]>hLimit) hLimit = low;
else if(arr[high]>hLimit) hLimit = high;
else hLimit = n+1;
cout<<hLimit-lLimit<<endl;}
}
}
}