Pagini recente » Cod sursa (job #756797) | Cod sursa (job #2982602) | Cod sursa (job #1838955) | Cod sursa (job #2982603) | Cod sursa (job #1838730)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
#define MOD 666013
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
vector <int> Hash[MOD + 1];
int poz;
inline int Key(int x) {
return x % MOD;
}
int Exist(int x) {
vector <int> :: iterator it;
int aux = Key(x);
for (it = Hash[aux].begin(); it < Hash[aux].end(); ++it)
if (*it == x)
return it - Hash[aux].begin();
return -1;
}
void Insert(int x) {
Hash[Key(x)].push_back(x);
}
void Delete(int x) {
int aux = Key(x);
Hash[aux].erase(Hash[aux].begin() + poz);
}
int main() {
int N;
fin >> N;
for (int i = 1; i <= N; ++i) {
int type, x;
fin >> type >> x;
poz = Exist(x);
if (type == 1 && poz == -1) {
Insert(x);
continue;
}
if (type == 2 && poz != -1) {
Delete(x);
continue;
}
if (type == 3)
fout << (poz == -1 ? 0 : 1) << "\n";
}
return 0;
}