Pagini recente » Cod sursa (job #2174567) | Cod sursa (job #2214229) | Cod sursa (job #2381636) | Cod sursa (job #2258489) | Cod sursa (job #2292584)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
const int MOD = 196613;
vector <int> a[MOD];
void add(int);
void eraseElement(int);
int isElement(int);
int main() {
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int query;
f >> query;
while (query--) {
int type, x;
f >> type >> x;
if (type == 1) { add(x);}
if (type == 2) { eraseElement(x);}
if (type == 3) { g << isElement(x) << "\n";}
}
return 0;
}
void add(int x) {
int key = x % MOD;
bool found = false;
for (int i = 0; i < a[key].size(); ++i) {
if (a[key][i] == x) { found = true;}
else if (a[key][i] == -1) {
found = true;
a[key][i] = x;
}
}
if ( !found ) {
a[key].push_back(x);
}
}
void eraseElement(int x) {
int key = x % MOD;
bool found = false;
for (int i = 0; i < a[key].size(); ++i) {
if (a[key][i] == x) {
found = true;
a[key][i] = -1; /// marchez ca sters
}
}
}
int isElement(int x) {
int key = x % MOD;
int found = 0;
for (int i = 0; i < a[key].size() && found == 0; ++i) {
if (a[key][i] == x) {
found = 1;
}
}
return found;
}