Cod sursa(job #1518751)

Utilizator valentinpielePiele Valentin valentinpiele Data 6 noiembrie 2015 12:34:19
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
#include <fstream>
#include <vector>
#define mod 666013
#define cheie x%mod

using namespace std;

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

int N, tip, x;
vector <int> H[666013];

int cauta (int x)
{
    for(int i = 0; i < H[cheie].size(); i ++)
        if(H[cheie][i] == x) return i;
    return -1;
}

void adauga (int x) { H[cheie].push_back(x); }

void sterge (int x)
{
    int pozitie;
    pozitie = cauta(x);
    if(pozitie == - 1) return;
    swap(H[cheie][pozitie], H[cheie][H[cheie].size()-1]);
    H[cheie].pop_back();
}

int main ()
{
    f >> N;

    for(int i = 1; i <= N; i ++)
    {

        f >> tip >> x;

        if(tip == 1) adauga(x);
        if(tip == 2) sterge(x);
        if(tip == 3)
        {
            if(cauta(x) != - 1) g << "1" << '\n';
            else g << "0" << '\n';
        }
    }
    return 0;
}