Pagini recente » Cod sursa (job #785488) | Cod sursa (job #620930) | Cod sursa (job #544749) | Cod sursa (job #2443516) | Cod sursa (job #1700925)
#include <iostream>
#include <fstream>
using namespace std;
#define ma 666613
ifstream f("hashuri.in");
ofstream g("hashuri.out");
struct nod
{
int info;
nod *urm;
}*v[ma];
int n, a, b;
int que( int p, int b )
{
nod*it = v[p];
while( it )
{
if( it->info == b )
return 1;
it = it->urm;
}
return 0;
}
void add( int p, int b )
{
nod *nou;
nou = new nod;
nou->info = b;
nou->urm = v[p];
v[p] = nou;
}
void del( int p, int b )
{
nod *p1, *p2;
p1 = v[p];
if(p1->info == b )
{
v[p] = p1->urm;
delete p1;
}
else
{
p1 = p1->urm;
p2 = v[p];
while( p1->info != b )
{
p2 = p1;
p1 = p1->urm;
}
p2->urm = p1->urm;
p1->urm = NULL;
delete p1;
}
}
int main()
{
f >> n;
for( int i=1; i<=n; ++i )
{
f >> a >> b;
int p = b%ma;
int x = que(p, b);
if( a == 3 )
{
g << x << '\n';
}
if( a == 1 && x == 0 )
{
add(p, b);
}
if( a == 2 && x == 1 )
{
del(p, b);
}
}
return 0;
}