Pagini recente » Cod sursa (job #2238528) | Cod sursa (job #1321315) | Cod sursa (job #1383307) | Cod sursa (job #2359244) | Cod sursa (job #2536249)
#include <bits/stdc++.h>
#define mod 666013
#define nax (1e6 + 3)
#define pb push_back
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector<int> mat[mod];
int n;
int Hashing(const int& x)
{
return x % mod;
}
bool Exista(const int& x)
{
int row = Hashing(x);
for(auto& it : mat[row])
if(it == x)
return true;
return false;
}
void Adauga(const int& x)
{
if(!Exista(x))
{
int row = Hashing(x);
mat[row].pb(x);
}
}
void Elimina(const int& x)
{
int row = Hashing(x);
for(size_t i = 0; i < mat[row].size(); ++i)
if(mat[row][i] == x)
{
mat[row].erase(mat[row].begin() + i);
return;
}
}
void Read()
{
int i = 1, c, x;
f >> n;
for(; i <= n; ++i)
{
f >> c >> x;
if(c == 1)
Adauga(x);
else if(c == 2)
Elimina(x);
else
g << Exista(x) << "\n";
}
}
int main()
{
ios::sync_with_stdio(false);
Read();
return 0;
}