Pagini recente » Clasamentul arhivei Infoarena Monthly | Cod sursa (job #2553182) | Cod sursa (job #1646599) | Cod sursa (job #2049243) | Cod sursa (job #1396955)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define Mod 666013
FILE *f = fopen ( "hashuri.in", "r" );
FILE *g = fopen ( "hashuri.out", "w" );
vector < int > Hash[Mod+1];
int poz;
inline int Key ( int x ){
return x % Mod;
}
int Exist ( int x ){
vector < int > :: iterator it;
int aux = Key ( x );
for ( it = Hash[aux].begin(); it < Hash[aux].end(); ++it )
if ( *it == x )
return it - Hash[aux].begin();
return -1;
}
void Insert ( int x ){
Hash[Key(x)].push_back ( x );
}
void Delete ( int x ){
int aux = Key ( x );
Hash[aux].erase ( Hash[aux].begin() + poz );
}
int main(){
int N, type, x, aux;
fscanf ( f, "%d", &N );
for ( int i = 1; i <= N; ++i ){
fscanf ( f, "%d%d", &type, &x );
aux = Key ( x );
poz = Exist ( x );
if ( type == 1 && poz == -1 ){
Insert ( x );
continue;
}
if ( type == 2 && poz != -1 ){
Delete ( x );
continue;
}
if ( type == 3 )
fprintf ( g, "%d\n", poz == -1 ? 0 : 1 );
}
return 0;
}