-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashPointsAndSegments.java
More file actions
57 lines (51 loc) · 1.23 KB
/
HashPointsAndSegments.java
File metadata and controls
57 lines (51 loc) · 1.23 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
55
56
57
import java.util.Scanner;
import java.io.*;
import java.util.HashMap;
import java.lang.Integer;
class HashPointsAndSegments {
public static final int MAX = 100000000;
public static void main(String[] args) {
Scanner in = new Scanner(new InputStreamReader(System.in));
int numSegments = in.nextInt();
int numPoints = in.nextInt();
int[] posArr = new int[MAX+1];
for(int i = 0; int i <= MAX){
posArr[i] = 0;
}
int[] negArr = new int[MAX+1];
for(int i = 0; int i <= MAX){
negArr[i] = 0;
}
int segStart;
int segEnd;
int count;
for(int i = 1; i <= numSegments; i++){
segStart = in.nextInt();
segEnd = in.nextInt();
if(segStart >= 0 && segEnd >= 0){
for(int j = segStart; j <= segEnd; j++){
posArr[j] = posArr[j] + 1;
}
}
else if(segStart < 0 && segEnd < 0){
for(int j = -segEnd; j <= -segStart; j+=){
negArr[j] = negArr[j] + 1;
}
}
else{
for(int j = -segStart; j > 0; j--){
negArr[j] = negArr[j] + 1;
}
for(int k = 0; k <= segEnd; k++){
posArr[k] = posArr[k] + 1;
}
}
}
for(int i = 1; i <= numPoints; i++){
point = in.nextInt();
if(point >= 0)
System.out.println(posArr[point]);
else System.out.println(negArr[point]);
}
}
}