Pagini recente » Cod sursa (job #2308184) | Cod sursa (job #803318) | Monitorul de evaluare | Cod sursa (job #2220630) | Cod sursa (job #1443555)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int M = 666019;
int n;
int val[1000001], urm[1000001], lst[M], nr = 0;
void adauga( long long int x )
{
int r = x % M;
nr++;
val[nr] = x;
urm[nr] = lst[r];
lst[r] = nr;
}
bool cauta( long long int x )
{
int p = lst[x % M];
while( p != 0 )
{
if ( val[p] == x )
return true;
p = urm[p];
}
return false;
}
void sterge( long long int x )
{
int r = x%M, p;
p = lst[r];
if ( val[p] == x )
{
lst[r] = urm[p];
return;
}
while( urm[p] != 0 )
{
if ( val[ urm[p] ] == x )
{
urm[p] = urm[urm[p]];
return;
}
p = urm[p];
}
}
int main()
{
long long int x;
int p;
in >> n;
for ( int i = 1; i <= n; i++ )
{
in >> p >> x;
if ( p == 1 )
{
if ( cauta(x) == false )
adauga(x);
}
if ( p == 2 )
{
sterge(x);
}
if ( p == 3 )
{
if ( cauta(x) == true )
out << 1 <<'\n';
else out << 0 <<'\n';
}
}
return 0;
}