-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11663.cpp
More file actions
46 lines (45 loc) · 894 Bytes
/
11663.cpp
File metadata and controls
46 lines (45 loc) · 894 Bytes
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
#include <iostream>
#include <algorithm>
#define MAX 100000
using namespace std;
int N, M;
long long arr[MAX + 1];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N >> M;
for (int n = 0; n < N; n++) {
cin >> arr[n];
}
sort(arr, arr + N);
while (M--) {
long long X, Y; cin >> X >> Y;
long long start = 0, end = N - 1, ans1 = 0, ans2 = 0;
while (start <= end) {
long long mid = (start + end) / 2;
if (X <= arr[mid]) {
//ans1 = mid;
end = mid - 1;
}
else {
start = mid + 1;
}
}
ans1 = start;
start = 0; end = N - 1;
while (start <= end) {
long long mid = (start + end) / 2;
if (arr[mid] <= Y) {
//ans2 = mid;
start = mid + 1;
}
else {
end = mid - 1;
}
}
ans2 = end;
cout << ans2 - ans1 + 1 << "\n";
//cout << "ans1 : " << ans1 << "\t" << "ans2 : " << ans2 << endl;
}
return 0;
}