Cod sursa(job #2722653)

Utilizator AndreiD31Dragan Andrei AndreiD31 Data 13 martie 2021 09:39:23
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>
#define mod 1000007

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

vector <int> v[1000010];

void adauga_in_hash(int val)
{
    int poz=val%mod;
    for(int i=0;i<v[poz].size();i++)if(v[poz][i]==val)return;

    v[poz].push_back(val);
}

int verifica_in_hash(int val)
{
    int poz=val%mod;
    for(int i=0;i<v[poz].size();i++)if(v[poz][i]==val)return 1;
    return 0;
}

void sterge_din_hash(int val)
{
    int poz=val%mod;
    for(int i=0;i<v[poz].size();i++)if(v[poz][i]==val){
            v[poz].erase(v[poz].begin()+i);
            return;
    }
}

int n,i,poz,x;
int main()
{
    f>>n;
    for(i=1;i<=n;i++)
    {
        f>>poz>>x;
        if(poz==1)adauga_in_hash(x);
        else if(poz==2)sterge_din_hash(x);
        else g<<verifica_in_hash(x)<<'\n';
    }
    return 0;
}