Pagini recente » Cod sursa (job #2840520) | Cod sursa (job #1248385) | Cod sursa (job #1110526) | Cod sursa (job #1208182) | Cod sursa (job #1202788)
#include <fstream>
#include <iostream>
#include <vector>
#include <bitset>
#include <string.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;
const char infile[] = "hashuri.in";
const char outfile[] = "hashuri.out";
ifstream fin(infile);
ofstream fout(outfile);
const int MAXN = 100005;
const int oo = 0x3f3f3f3f;
typedef vector<int> Graph[MAXN];
typedef vector<int> :: iterator It;
const inline int min(const int &a, const int &b) { if( a > b ) return b; return a; }
const inline int max(const int &a, const int &b) { if( a < b ) return b; return a; }
const inline void Get_min(int &a, const int b) { if( a > b ) a = b; }
const inline void Get_max(int &a, const int b) { if( a < b ) a = b; }
class HashTable {
private:
const static int MOD = 666013;
vector <int> v[MOD];
public:
bool insert(int value) {
if(check(value))
return false;
int key = getKey(value);
v[key].push_back(value);
return true;
}
bool erase(int value) {
int key = getKey(value);
for(It it = v[key].begin() ; it != v[key].end(); ++ it)
if(*it == value) {
v[key].erase(it);
return true;
}
return false;
}
bool check(int value) {
int key = getKey(value);
for(It it = v[key].begin() ; it != v[key].end(); ++ it)
if(*it == value)
return true;
return false;
}
inline int getKey(int value) {
return value % MOD;
}
};
int m;
HashTable H;
int main() {
fin >> m;
for( ; m ; -- m) {
int op, x;
fin >> op >> x;
switch(op) {
case 1:
H.insert(x);
break;
case 2:
H.erase(x);
break;
case 3:
fout << H.check(x) << '\n';
break;
}
}
fin.close();
fout.close();
return 0;
}