Cod sursa(job #2439532)

Utilizator DavidLDavid Lauran DavidL Data 16 iulie 2019 11:44:00
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.17 kb
#include <bits/stdc++.h>
#define cin fi
#define cout fo
using namespace std;
ifstream fi("hashuri.in");
ofstream fo("hashuri.out");

const int MOD = 10000019;

int n;
list <int> h[MOD - 1];

inline int f(int x)
{
    return x - x / MOD * MOD;
}

void baga(int x)
{
    int val = f(x);

    bool este = 0;
    for (auto it = h[val].begin(); it != h[val].end(); it++)
        if ((*it) == x)
            este = 1;

    if (!este)
        h[val].push_back(x);
}

void scoate(int x)
{
    int val = f(x);

    for (auto it = h[val].begin(); it != h[val].end(); it++)
        if ((*it) == x)
            it = h[val].erase(it);
}

bool verif(int x)
{
    int val = f(x);

    for (auto it = h[val].begin(); it != h[val].end(); it++)
        if ((*it) == x)
            return 1;
    return 0;
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int op, x;
        cin >> op >> x;
        if (op == 1)
        {
            baga(x);
        }
        else if (op == 2)
        {
            scoate(x);
        }
        else 
        {
            cout << verif(x) << "\n";
        }
    }

    return 0;
}