Pagini recente » Cod sursa (job #2854221) | Cod sursa (job #2866646) | Cod sursa (job #237230) | Cod sursa (job #2019227) | Cod sursa (job #613345)
Cod sursa(job #613345)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
const int P = 666013;
vector <int> hash[P];
void add(int v){
int idx = v % P;
vector<int>::iterator it;
it = find(hash[idx].begin(), hash[idx].end(), v);
if ( it == hash[idx].end())
hash[idx].push_back(v);
}
void rem(int v){
int idx = v % P;
vector<int>::iterator it;
it = find(hash[idx].begin(), hash[idx].end(), v);
if ( it != hash[idx].end())
hash[idx].erase(it);
}
int contain(int v){
int idx = v % P;
vector<int>::iterator it;
it = find(hash[idx].begin(), hash[idx].end(), v);
if ( it != hash[idx].end())
return 1;
return 0;
}
int main(){
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n, op, v;
fin >> n;
for (int i = 0; i < n; i++) {
fin >> op >> v;
if ( op == 1)
add(v);
if ( op == 2)
rem(v);
if ( op == 3)
fout << contain(v) << '\n';
}
return 0;
}