Cod sursa(job #828815)

Utilizator Victor10Oltean Victor Victor10 Data 4 decembrie 2012 15:04:01
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.92 kb
#include <fstream>
#include <vector>
using namespace std;
#define MOD 666013

vector <int> v [MOD + 5];

int get_poz (int x)
{
    int poz, n, i;
    poz = x % MOD;
    n = v [poz] . size ();
    for (i = 0; i < n; ++ i)
        if (v [poz] [i] == x) return i;
    return -1;
}

int main()
{
    ifstream f ("hashuri.in");
    ofstream g ("hashuri.out");
    int n, i, poz, pozx, x, op;
    f >> n;

    for (i = 0; i < n; ++ i)
    {
        f >> op >> x;
        poz = x % MOD;
        pozx = get_poz (x);
        if (op == 1)
        {
            if (pozx == -1)
                v [poz] . push_back (x);
        }
        if (op == 2)
        {
            if (pozx != -1)
                v [poz] . erase (v [poz] . begin () + pozx);
        }
        if (op == 3)
        {
            if (pozx == -1) g << 0;
            else g << 1;
            g << '\n';
        }
    }

    return 0;
}