Pagini recente » Profil Prodan | Borderou de evaluare (job #791102) | Profil FlashNUT | Cod sursa (job #2640058) | Cod sursa (job #2622633)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int mod = 666013;
vector<int> hashT[mod];
bool cauta(int x)
{
int hashValue = x % mod;
for (auto i : hashT[hashValue]) {
if (i == x)
return true;
}
return false;
}
void inserare(int x)
{
if (!cauta(x)) {
int hashValue = x % mod;
hashT[hashValue].push_back(x);
}
}
void stergere(int x)
{
if (cauta(x)) {
int hashValue = x % mod;
for (unsigned i=0; i<hashT[hashValue].size(); i++) {
if (hashT[hashValue][i] == x) {
hashT[hashValue].erase(hashT[hashValue].begin() + i);
break;
}
}
}
}
int main()
{
int n,op,x;
fin>>n;
for (int i=0; i<n; i++) {
fin>>op>>x;
switch(op) {
case 1:
inserare(x);
break;
case 2:
stergere(x);
break;
case 3:
fout<<cauta(x)<<'\n';
break;
}
}
}