Pagini recente » Cod sursa (job #1758473) | Cod sursa (job #1424426) | Cod sursa (job #2675578) | Cod sursa (job #1327007) | Cod sursa (job #2703688)
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static class BRGIntHash {
private static final int PRIME = 666013;
public List<Integer>[] hashBuckets = new ArrayList[PRIME];
public void push(int n) {
int key = n % PRIME;
if (contains(n)) return;
if (hashBuckets[key] == null) {
hashBuckets[key] = new ArrayList<>();
}
hashBuckets[key].add(n);
}
public void erase(int n) {
int key = n % PRIME;
if (hashBuckets[key] == null) {
return;
}
hashBuckets[key].remove(Integer.valueOf(n));
}
public boolean contains(int n) {
int key = n % PRIME;
if (hashBuckets[key] == null) {
return false;
}
for (Integer val : hashBuckets[key]) {
if (val == n) {
return true;
}
}
return false;
}
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileReader("hashuri.in"));
PrintWriter pw = new PrintWriter("hashuri.out");
Set<Integer> set = new HashSet<>();
BRGIntHash hash = new BRGIntHash();
int n = sc.nextInt();
while (n-- > 0) {
int op = sc.nextInt();
int nbr = sc.nextInt();
if (op == 1) hash.push(nbr);
if (op == 2) hash.erase(nbr);
if (op == 3) pw.println(hash.contains(nbr) ? 1 : 0);
}
pw.flush();
}
}