Pagini recente » Cod sursa (job #1855835) | Cod sursa (job #2869162) | Cod sursa (job #2428018) | Cod sursa (job #1817403) | Cod sursa (job #1081839)
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>
#include <iomanip>
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
const int Nmax = 1000009;
const int M = 168001;
const int C1 = 29;
const int C2 = 37;
int N; int V[Nmax]; int Tabel[M + 1];
int hash(int X, int Try) {
return (X + C1 * Try + Try * C2 * Try) % M;
}
void insert(int X) {
int Try = 0;
do{
if(Tabel[hash(X, Try)] == 0) {
Tabel[hash(X, Try)] = X; return;
} else ++Try;
}while(1);
}
void del(int X) {
int Try = 0;
do{
if(Tabel[hash(X, Try)] == X) {
Tabel[hash(X, Try)] = 0; return;
} else ++Try;
}while(Try < 200);
}
int search(int X) {
int Try = 0;
do{
if(Tabel[hash(X, Try)] == X)
return 1;
else
++Try;
}while(Try < 200);
return 0;
}
void Read() {
fin >> N;
for(int A, type, i = 1; i <= N; ++i) {
fin >> type >> A;
switch(type) {
case 1: insert(A); break;
case 2: del(A); break;
case 3: fout << search(A) << '\n'; break;
}
}
}
int main() {
Read ();
return 0;
}