题目描述
blablabla
样例
blablabla
算法1
Java 代码
import java.io.*;
import java.util.*;
public class Main{
static int N = 100003;
static int[] h = new int[N];
static int[] e = new int[N];
static int[] ne = new int[N];
static int idx;
static void insert(int x){
// set Hash key make positive
int k = (x % N + N) % N;
e[idx] = x;
ne[idx] = h[k];
h[k] = idx++;
}
static boolean find(int x){
int k = (x % N + N) % N;
for(int i = h[k] ; i != -1 ; i = ne[i]){
if(e[i] == x) return true;
}
return false;
}
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.valueOf(br.readLine());
for(int i=0;i<N;i++){
h[i]=-1;
}
while(n-- > 0){
String[] s = br.readLine().split("\\s+");
int x = Integer.valueOf(s[1]);
if(s[0].equals("I")){
insert(x);
}else{
if(find(x)) System.out.println("Yes");
else System.out.println("No");
}
}
}
}