Pagini recente » Cod sursa (job #2433424) | Cod sursa (job #1770437) | Cod sursa (job #745941) | Cod sursa (job #128036) | Cod sursa (job #1455757)
#include <vector>
#include <list>
#include <fstream>
#include <algorithm>
using namespace std;
constexpr int table_sz = 1426231;
class myhash{
vector<list<long long> > buckete;
public:
myhash(bool):
buckete(table_sz){}
void erase(const long long x){
auto& buc = buckete[x%table_sz];
auto it = find(begin(buc), end(buc), x);
if(it != end(buc)){
buc.erase(it); } }
bool _find(const long long x){
const auto& buc = buckete[x%table_sz];
return find(begin(buc), end(buc), x) !=
end(buc); }
void insert(const long long x){
if(!_find(x)){
buckete[x%table_sz].push_back(x); } } };
int main(){
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n;
f >> n;
int tip;
long long val;
myhash hs(true);
for(int i = 0; i < n; ++i){
f >> tip >> val;
switch(tip){
case 1:
hs.insert(val);
break;
case 2:
hs.erase(val);
break;
case 3:
g << hs._find(val) << '\n';
break; } }
return 0; }