Cod sursa(job #2777025)

Utilizator Edyci123Bicu Codrut Eduard Edyci123 Data 21 septembrie 2021 21:13:58
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.11 kb
#include <bits/stdc++.h>
#define MOD 666013

using namespace std;

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

int n, ops;
vector <int> G[MOD];

vector <int>::iterator find_value(int val)
{
    int hashCode = val % MOD;
    for(vector <int>::iterator it = G[hashCode].begin(); it < G[hashCode].end(); it++)
        if(*it == val)
            return it;
    return G[hashCode].end();
}

void insert_value(int val)
{
    int hashCode = val % MOD;
    if(find_value(val) == G[hashCode].end())
        G[hashCode].push_back(val);
}

void erase_value(int val)
{
    int hashCode = val % MOD;
    vector <int>::iterator it = find_value(val);
    if(it != G[hashCode].end())
        G[hashCode].erase(it);
}

int main()
{
    f >> n;

    for(int i = 1; i <= n; i++)
    {
        int x;
        f >> ops >> x;
        if(ops == 1)
            insert_value(x);
        if(ops == 2)
            erase_value(x);
        if(ops == 3)
        {
            int hashCode = x % MOD;
            g << (find_value(x) != G[hashCode].end()) << "\n";
        }

    }

    return 0;
}