Cod sursa(job #1549334)

Utilizator Vele_GeorgeVele George Vele_George Data 12 decembrie 2015 11:29:26
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <vector>
#define p 6660131
using namespace std;

vector<int> v[p];

int found(int x)
 {
    int h = x % p;
    for(int i=0; i<v[h].size(); i++)
    {
        if (v[h][i] == x) return i;
    }
    return -1;
}

void add(int x)
{
    if (found(x) != -1) return;

    int h = x % p;
    v[h].push_back(x);
    return;
}

void erase(int x)
{
    int poz = found(x);
    if (poz == -1) return;
    int h = x % p;

    swap(v[h][poz], v[h].back());
                    v[h].pop_back();
    return;

}

int main()
{
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    int n, act, x;
    f >> n;
    for(int i=1; i<=n; i++)
    {
        f >> act >> x;
        if (act == 1) add(x);
        else
        if (act == 2) erase(x);
        else
        if (found(x) == -1) g << "0\n";
                     else  g << "1\n";
    }

    f.close();
    g.close();
    return 0;
}