Cod sursa(job #2861903)

Utilizator alexmorosanuMorosanu Alexandru alexmorosanu Data 4 martie 2022 17:42:30
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.85 kb
#include <fstream>
#include <vector>
#define M 666013
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
vector <int> v[666020];
int hashfind(int x)
{
    int k=x%M;
    for(int i=0;i<v[k].size();i++)
        if(v[k][i]==x)
        return i;
    return -1;
}
void hashin(int x)
{
    int k=x%M;
    if(hashfind(x)==-1)
        v[k].push_back(x);
}
void hashout(int x)
{
    int k=x%M,l=hashfind(x);
    if(l>-1)
        v[k].erase(v[k].begin()+l);
}
int n,i,c,x;
int main()
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>c>>x;
        if(c==1)
            hashin(x);
        else
        if(c==2)
            hashout(x);
        else
        {
            c=hashfind(x);
            if(c==-1)
                g<<0<<'\n';
            else
                g<<1<<'\n';
        }
    }
    return 0;
}