Cod sursa(job #1765052)

Utilizator ionutpop118Pop Ioan Cristian ionutpop118 Data 26 septembrie 2016 11:26:16
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <cstdio>
#include <vector>

using namespace std;
const int mod = 666019;
vector <int> g[mod];
inline vector<int>::iterator MyFind(int x)
{
    int poz = x % mod;
    vector<int>::iterator it;

    for (it = g[poz].begin(); it != g[poz].end(); ++it)
        if (*it == x)
            return it;
    return g[poz].end();
}

void adaug (int x)
{
    int poz = x % mod;
    if (MyFind(x) == g[poz].end())
        g[poz].push_back(x);
}
void scot (int x)
{
    int poz = x % mod;
    vector <int>::iterator it = MyFind(x);
    if (it != g[poz].end())
        g[poz].erase(it);
}
bool query (int x)
{
    int poz = x % mod;
    if (MyFind(x) != g[poz].end())
        return 1;
    return 0;
}
int main()
{
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    int n, tip, x;

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d %d", &tip, &x);
        if (tip == 1) adaug(x);
        else if (tip == 2) scot(x);
        else printf("%d\n", query(x));
    }
    return 0;
}