Cod sursa(job #2716083)

Utilizator Rares09Rares I Rares09 Data 4 martie 2021 18:17:51
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.09 kb
#include <fstream>
#include <list>

using namespace std;

ifstream cin ("hashuri.in");
ofstream cout ("hashuri.out");

list <int> v[666032];

int hashMe(int x)
{
    return x % 666013;
}

void add(int x)
{
    int y = hashMe(x);

    for(auto it = v[y].begin(); it != v[y].end(); ++it)
    {
        if(*it == x)
            return;
    }

    v[y].push_back(x);
}

void del(int x)
{
    int y = hashMe(x);

    for(auto it = v[y].begin(); it != v[y].end(); ++it)
    {
        if(*it == x)
        {
            v[y].erase(it);
            break;
        }
    }
}

bool chk(int x)
{
    int y = hashMe(x);

    for(auto it = v[y].begin(); it != v[y].end(); ++it)
    {
        if(*it == x)
        {
            return 1;
        }
    }

    return 0;
}

int main()
{
    int n;
    cin >> n;

    for(int i = 1; i <= n; ++i)
    {
        int a, b;
        cin >> a >> b;

        if(a == 1)
            add(b);
        else if(a == 2)
            del(b);
        else if(a == 3)
            cout << chk(b) << '\n';
    }

    return 0;
}