-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path11663.js
More file actions
48 lines (43 loc) · 1.01 KB
/
11663.js
File metadata and controls
48 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
/*
일단 점 정렬
선분의 시작을 이분탐색
선분의 끝을 이분탐색
*/
const INPUT_FILE = process.platform === 'linux' ? '/dev/stdin' : './input';
const [, points, ...lines] = require('fs')
.readFileSync(INPUT_FILE)
.toString()
.trim()
.split('\n')
.map((line) => line.split(' ').map(Number));
points.sort((one, another) => one - another);
const findLeftIndex = (value) => {
let left = 0;
let right = points.length;
while (left < right) {
const mid = Math.floor((left + right) / 2);
if (value <= points[mid]) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
};
const findRightIndex = (value) => {
let left = 0;
let right = points.length;
while (left < right) {
const mid = Math.floor((left + right) / 2);
if (value < points[mid]) {
right = mid;
} else {
left = mid + 1;
}
}
return left;
};
const sol = lines.map(([left, right]) => {
return findRightIndex(right) - findLeftIndex(left);
});
console.log(sol.join('\n'));