-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbcount.java
56 lines (40 loc) · 1.58 KB
/
bcount.java
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
import java.io.*;
import java.util.*;
public class bcount {
public static void main(String[] args) throws IOException {
// write your code here
BufferedReader f = new BufferedReader(new FileReader("bcount.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("bcount.out")));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
int k = Integer.parseInt(st.nextToken());
ArrayList<Integer> first = new ArrayList<Integer>();
ArrayList<Integer> second = new ArrayList<Integer>();
ArrayList<Integer> third = new ArrayList<Integer>();
first.add(0);
second.add(0);
third.add(0);
for(int i = 0; i<n;i++){
int m = Integer.parseInt(f.readLine());
first.add(first.get(i));
second.add(second.get(i));
third.add(third.get(i));
if(m == 1){
first.set(i+1,first.get(i)+1);
} else if(m==2){
second.set(i+1,second.get(i)+1);
} else{
third.set(i+1,third.get(i)+1);
}
}
for(int i = 0; i<k;i++){
st = new StringTokenizer(f.readLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
out.print(first.get(end)-first.get(start-1)+" ");
out.print(second.get(end)-second.get(start-1)+" ");
out.println(third.get(end)-third.get(start-1));
}
out.close();
}
}