Cod sursa(job #3131941)

Utilizator sirbu27Sirbu Iulia-Georgiana sirbu27 Data 21 mai 2023 21:52:31
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
#define constanta 666013
vector<int> h[666013];

void insert(int val)
{
    int hf = val % constanta;
    for (auto i : h[hf])
        if (i == val)
        {
            return;
        }
    h[hf].push_back(val);
}

int find(int val)
{
    int hf = val % constanta;
    for (auto i : h[hf])
        if (i == val)
            return 1;
    return 0;
}

void remove(int val)
{
    int hf = val % constanta;
    for (int i = 0; i < h[hf].size(); i++)
        if (h[hf][i] == val)
            h[hf].erase(h[hf].begin() + i);
}

int main()
{
    int N;
    fin >> N;
    for (int i = 1; i <= N; i++)
    {
        int opt, val;
        fin >> opt >> val;
        switch (opt)
        {
        case 1:
            insert(val);
            break;

        case 2:
            remove(val);
            break;

        case 3:
            fout << find(val) << endl;
        }
    }
    return 0;
}