Cod sursa(job #1051975)

Utilizator Theodor1000Cristea Theodor Stefan Theodor1000 Data 10 decembrie 2013 19:32:05
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <vector>

#define M 666013
#define pb push_back

using namespace std;

vector <int> h[M];
vector <int> :: iterator it;

int x, ind;

vector <int> :: iterator gaseste ()
{
    for (it = h[ind].begin (); it != h[ind].end (); it++)
        if (*it == x) return it;

    return it;
}

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

    int n;

    f >> n;

    for (int i = 1; i <= n; i++)
    {
        int op;

        f >> op >> x;

        ind = x % M;
        it = gaseste ();

        if (op == 1)
            if (it == h[ind].end ()) h[ind].pb (x);

        if (op == 2)
            if (it != h[ind].end ()) h[ind].erase (it);

        if (op == 3)
            if (it != h[ind].end ()) g << "1\n";
            else g << "0\n";
    }

    return 0;
}