Pagini recente » Cod sursa (job #66226) | Cod sursa (job #2491323) | Cod sursa (job #1994160) | Cod sursa (job #581721) | Cod sursa (job #2646308)
#include <fstream>
using namespace std;
const int N = 1000001;
const int M = 666019;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int val[N], urm[N], lst[M], nr;
bool part(int x)
{
int c = x % M;
for (int p = lst[c]; p != 0; p = urm[p])
{
if (val[p] == x)
{
return true;
}
}
return false;
}
void add(int x)
{
int c = x % M;
if (part(x))
{
return;
}
val[++nr] = x;
urm[nr] = lst[c];
lst[c] = nr;
}
void del(int x)
{
int c = x % M, p = lst[c];
while (p != 0 && val[p] != x)
{
p = urm[p];
}
if (p != 0)
{
val[p] = val[lst[c]];
lst[c] = urm[lst[c]];
}
}
int main()
{
int n, tip, val;
in >> n;
for (int i = 0; i < n; i++)
{
in >> tip >> val;
if (tip == 1)
{
add(val);
}
else if (tip == 2)
{
del(val);
}
else
{
out << part(val) << '\n';
}
}
in.close();
out.close();
return 0;
}