Pagini recente » Cod sursa (job #351894) | Cod sursa (job #1185077) | Cod sursa (job #1799710) | Cod sursa (job #235198) | Cod sursa (job #1893447)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
#define ui unsigned int
ifstream f("hashuri.in");
ofstream g("hashuri.out");
struct HASH {
private:
static const int SZ = 666013;
vector <int> h[SZ];
public:
inline int push(int el) {
ui key = el % SZ;
h[key].push_back(el);
}
inline bool pop(int el) {
ui key = el % SZ;
for(ui i = 0;i < h[key].size();i++) {
if(h[key][i] == el) {
swap(h[key][i], h[key][h[key].size() - 1]);
h[key].pop_back();
return true;
}
}
return false;
}
inline bool find(int el) {
ui key = el % SZ;
for(ui i = 0;i < h[key].size();i++) {
if(h[key][i] == el) {
return true;
}
}
return false;
}
};
HASH hh;
int main() {
int N;
f >> N;
for(int i = 0;i < N;i++) {
int op, x;
f >> op >> x;
switch(op) {
case 1:
hh.push(x);
break;
case 2:
hh.pop(x);
break;
case 3:
g << hh.find(x) << "\n";
break;
}
}
f.close();
g.close();
return 0;
}