Pagini recente » Cod sursa (job #1956520) | Cod sursa (job #2146824) | Cod sursa (job #1594812) | Cod sursa (job #825627) | Cod sursa (job #944446)
Cod sursa(job #944446)
#include <iostream>
#include <fstream>
#include <algorithm>
#include <forward_list>
#include <vector>
using namespace std;
class HashSet {
public:
HashSet() {
table.resize(mod);
}
void insert( int x ) {
int r = x % mod;
if ( find( table[r].begin(), table[r].end(), x ) == table[r].end() ) {
table[r].push_front(x);
}
}
void remove( int x ) {
int r = x % mod;
table[r].remove(x);
}
bool inSet( int x ) {
int r = x % mod;
return find( table[r].begin(), table[r].end(), x ) != table[r].end();
}
private:
static const int mod = 666013;
vector<forward_list<int> > table;
};
int main() {
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n;
fin >> n;
HashSet a;
for (int i = 0; i < n; ++i) {
int op, x;
fin >> op >> x;
switch (op) {
case 1: a.insert(x); break;
case 2: a.remove(x); break;
case 3: fout << a.inSet(x) << '\n'; break;
}
}
return 0;
}