Pagini recente » Cod sursa (job #860042) | Cod sursa (job #156402) | Cod sursa (job #1929867) | Cod sursa (job #2855542) | Cod sursa (job #2146928)
#include <bits/stdc++.h>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int nMax = 1000005;
const int mod = 100003;
struct Hash{
vector <int> v[nMax];
inline bool Search(int x) {
int lst = x % mod;
for(const auto& val : v[lst]) {
if(val == x) {
return true;
}
}
return false;
}
inline void Insert(int x) {
if(Search(x)) {
return;
}
int lst = x % mod;
v[lst].push_back(x);
}
inline void Del(int x) {
int lst = x % mod;
int len = v[lst].size();
for(int i = 0; i < len; i++) {
if(v[lst][i] == x) {
v[lst][i] = v[lst][len - 1];
v[lst].pop_back();
return;
}
}
}
};
Hash H;
int main()
{
int n, tip, x;
f >> n;
for(int i = 1; i <= n; i++) {
f >> tip >> x;
if(tip==1)
H.Insert(x);
else
if(tip==2)
H.Del(x);
else
g << H.Search(x) <<"\n";
}
return 0;
}