Pagini recente » Cod sursa (job #1907679) | Cod sursa (job #2080984) | Cod sursa (job #894262) | Cod sursa (job #1435998) | Cod sursa (job #1743548)
//package hashuri;
import java.io.*;
import java.util.*;
public class Main {
private static final int MOD = 666013;
public static void main(String[] args) throws IOException {
InputReader in = new InputReader(new FileInputStream("hashuri.in"));
PrintWriter out = new PrintWriter(new FileOutputStream("hashuri.out"));
new Main().solve(in, out);
out.close();
}
public void solve(InputReader in, PrintWriter out) {
int N = in.nextInt();
HashSet hash = new HashSet();
while (N-- > 0) {
int op = in.nextInt();
int value = in.nextInt();
if (op == 1)
hash.Insert(value);
else if (op == 2)
hash.Erase(value);
else {
if (hash.Check(value))
out.println("1");
else
out.println("0");
}
}
}
class HashSet {
private ArrayList<LinkedList<Integer>> hash_table = new ArrayList<LinkedList<Integer>>();
HashSet() {
for (int i = 0; i < MOD; ++i)
hash_table.add(new LinkedList<Integer>());
}
public void Insert(int value) {
int key = value % MOD;
for (int it: hash_table.get(key))
if (it == value)
return;
hash_table.get(key).add(value);
}
public boolean Check(int value) {
int key = value % MOD;
for (int it: hash_table.get(key))
if (it == value)
return true;
return false;
}
public void Erase(int value) {
int key = value % MOD;
for (int it: hash_table.get(key))
if (it == value) {
hash_table.get(key).remove((Object)it);
return;
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1)
throw new UnknownError();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new UnknownError();
}
if (numChars <= 0)
return -1;
}
return buf[curChar++];
}
public int peek() {
if (numChars == -1)
return -1;
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
return -1;
}
if (numChars <= 0)
return -1;
}
return buf[curChar];
}
public void skip(int x) {
while (x-- > 0)
read();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public String nextString() {
return next();
}
public String next() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuffer res = new StringBuffer();
do {
res.appendCodePoint(c);
c = read();
} while (!isSpaceChar(c));
return res.toString();
}
public String nextLine() {
StringBuffer buf = new StringBuffer();
int c = read();
while (c != '\n' && c != -1) {
if (c != '\r')
buf.appendCodePoint(c);
c = read();
}
return buf.toString();
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c)) {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public boolean hasNext() {
int value;
while (isSpaceChar(value = peek()) && value != -1)
read();
return value != -1;
}
private boolean isSpaceChar(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
}
}