Repository navigation
Expand file tree
/
Copy pathForFansofStatistics1613.java
More file actions
77 lines (68 loc) · 2.08 KB
/
Copy pathForFansofStatistics1613.java
File metadata and controls
77 lines (68 loc) · 2.08 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package timus;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;
/**
* Created by sherxon on 2016-12-10.
*/
public class ForFansofStatistics1613 {
public static void main(String[] args) throws IOException {
FastReader fastReader=new FastReader();
int n=fastReader.nextInt();
Map<Integer, TreeSet<Integer>> map= new HashMap<>(n);
int k;
for (int i = 1; i <= n; i++) {
k= fastReader.nextInt();
if(!map.containsKey(k))
map.put(k, new TreeSet<>());
map.get(k).add(i);
}
int m=fastReader.nextInt();
int from, to, j, res;
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(System.out));
for (int i = 0; i < m; i++) {
from=fastReader.nextInt();
to=fastReader.nextInt();
j=fastReader.nextInt();
res=0;
if(map.containsKey(j)) {
Integer fl=map.get(j).floor(to);
Integer ce=map.get(j).ceiling(from);
if(fl!=null && ce!=null && fl.compareTo(ce)>=0)res=1;
}
writer.write(String.valueOf(res));
writer.flush();
}
}
private static class FastReader {
BufferedReader bf;
StringTokenizer st;
public FastReader() {
bf=new BufferedReader(new InputStreamReader(System.in));
}
String nextLine(){
String st="";
try {
st=bf.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return st;
}
String next(){
while (st==null || !st.hasMoreTokens()){
try {
st= new StringTokenizer(bf.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt(){
return Integer.parseInt(next());
}
}
}