Cod sursa(job #2624911)

Utilizator RomanacheRoman Alexandru-George Romanache Data 5 iunie 2020 16:31:12
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <bits/stdc++.h>
#define mod 100003

using namespace std;

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

vector <pair<int,int> >v[100010];

void AddHash(int x)
{
    int rest=x%mod;
    for(int i=0;i<v[rest].size();i++)
    {
        if(v[rest][i].first=x)
        {
            v[rest][i].second=1;
            return;
        }
    }
    v[rest].push_back({x,1});
}

void DeleteHash(int x)
{
    int rest=x%mod;
    for(int i=0;i<v[rest].size();i++)
        if(v[rest][i].first==x)
        {
            v[rest][i].second=0;
            return;
        }
}

int VerifHash(int x)
{
    int rest=x%mod;
    for(int i=0;i<v[rest].size();i++)
        if(v[rest][i].first==x)
            return (v[rest][i].second);
    return 0;
}

int n,op,x,i;

int main()
{
    fin>>n;
    for(i=1;i<=n;i++)
    {
        fin>>op>>x;
        if(op==1)AddHash(x);
        else if(op==2)DeleteHash(x);
        else fout<<VerifHash(x)<<"\n";
    }

    return 0;
}