Pagini recente » Cod sursa (job #286811) | Cod sursa (job #1306391) | Cod sursa (job #1371442) | Cod sursa (job #2036391) | Cod sursa (job #2262420)
#include <bits/stdc++.h>
#define MaxN 1000005
#define MOD 666013
std::ifstream InFile("hashuri.in");
std::ofstream OutFile("hashuri.out");
int N;
template <int P> class HashTable {
public:
inline void Add(int x) {
int Index = x%P,
n = x/P;
ModList[Index].push_back(n);
}
inline void Erase(int x) {
int Index = x%P,
n = x/P;
for (std::list <int>::iterator It = ModList[Index].begin(); It != ModList[Index].end(); ++It)
if (*It == n)
ModList[Index].erase(It),
It = ModList[Index].end();
}
inline bool Find(int x) {
int Index = x%P,
n = x/P;
for (std::list <int>::iterator It = ModList[Index].begin(); It != ModList[Index].end(); ++It)
if (*It == n)
return 1;
return 0;
}
protected:
std::list <int> ModList[P];
}; HashTable <MOD> Hash;
int x;
inline void Query1() {
InFile >> x;
Hash.Add(x);
}
inline void Query2() {
InFile >> x;
Hash.Erase(x);
}
inline bool Query3() {
InFile >> x;
return Hash.Find(x);
}
void Citire() {
InFile >> N;
}
void Rezolvare() {
int Type;
while (N--) {
InFile >> Type;
if (Type == 1) {
Query1(Hash);
} else
if (Type == 2) {
Query2(Hash);
}
else
OutFile << Query3(Hash) << '\n';
}
}
int main()
{
Citire();
Rezolvare();
return 0;
}