Pagini recente » Cod sursa (job #2925937) | Cod sursa (job #2477774) | Cod sursa (job #458626) | Cod sursa (job #2806339) | Cod sursa (job #1413254)
#include <iostream>
#include <fstream>
#include <vector>
#include <unordered_set>
using namespace std;
const int maxn = 1000005;
const int mod = 666013;
int n;
vector <int> g[mod];
inline void solve_unordered_set() {
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
unordered_set<int> _hash;
fin >> n;
while(n -- ) {
int op, x;
fin >> op >> x;
if(op == 1) {
_hash.insert(x);
}
if(op == 2) {
_hash.erase(x);
}
if(op == 3)
fout << (_hash.find(x) != _hash.end()) << "\n";
}
}
inline bool find(int x) {
for(auto it : g[x % mod])
if(it == x)
return 1;
return 0;
}
inline void insert(int x) {
if(find(x))
return;
g[x % mod].push_back(x);
}
inline void erase(int x) {
if(!find(x))
return ;
for(vector <int> :: iterator it = g[x % mod].begin() ; it != g[x % mod].end() ; ++ it)
if(*it == x) {
g[x % mod].erase(it);
return ;
}
}
inline void solve_vector() {
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
fin >> n;
while(n -- ) {
int op, x;
fin >> op >> x;
if(op == 1)
insert(x);
if(op == 2)
erase(x);
if(op == 3)
fout << find(x) << '\n';
}
}
int main() {
//solve_unordered_set();
solve_vector();
}