Cod sursa(job #2909797)

Utilizator petru-robuRobu Petru petru-robu Data 15 iunie 2022 21:04:44
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
#include <iostream>
#include<vector>
using namespace std;
const int m=666013;
vector<int>table[m];
 
 
 
int hashfind(int x)
{
 int id=x%m;
 for(int i=0; i<table[id].size(); i++)
        if (x==table[id][i])return 1;
 return 0;
}
 
 
void hashinsert(int x)
{
   if(hashfind(x)==0) {
    int id=x%m;
    table[id].push_back(x);
 
   }
}
void hashdelete(int x)
{
    if(hashfind(x)==1){
        int id=x%m;
        for(int i=0; i<table[id].size(); i++)
        if(x==table[id][i]){swap(table[id][i], table[id][table[id].size()-1]);
        table[id].pop_back();}
    }
}
 
 
 
 
 
 
 
 
 
 
 
 
 
int main()
{
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    int N;
    scanf("%d", &N);
    for(;N-->0;)
    {
        int op,x;
        scanf("%d%d", &op, &x);
        if(op==1)hashinsert(x);
        if(op==2)hashdelete(x);
        if(op==3)printf("%d\n",hashfind(x));
    }
 
 
}