Pagini recente » Cod sursa (job #2522852) | Cod sursa (job #944449) | Cod sursa (job #347770) | Cod sursa (job #1891885) | Cod sursa (job #2657367)
#include <stdio.h>
#include <vector>
using namespace std;
const int NMAX = 1e6;
const int MOD = 666013;
vector <int> v[MOD];
void add_hash( int x ){
int i = 0, code = x % MOD;
while( i < v[code].size() && x != v[code][i] )
++i;
if( i == v[code].size() )
v[code].push_back(x);
}
bool search_hash( int x ){
int i = 0, code = x % MOD;
while( i < v[code].size() && x != v[code][i] )
++i;
return i < v[code].size();
}
void erase_hash( int x ){
int i = 0, code = x % MOD;
while( i < v[code].size() && x != v[code][i] )
++i;
if( i < v[code].size() )
v[code].erase(v[code].begin() + i);
}
int main() {
int n, op, x;
FILE *fin, *fout;
fin = fopen( "hashuri.in", "r" );
fout = fopen( "hashuri.out", "w" );
fscanf( fin, "%d", &n );
while( n-- ){
fscanf( fin, "%d%d", &op, &x );
if( op == 1 )
add_hash(x);
else if( op == 2 )
erase_hash(x);
else
fprintf( fout, "%d\n", search_hash(x) );
}
fclose( fin );
fclose( fout );
return 0;
}