Cod sursa(job #1912564)

Utilizator justsomedudePalade Thomas-Emanuel justsomedude Data 8 martie 2017 09:38:50
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <fstream>
#include <vector>

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

#define cheie 666013

vector < int > L[cheie];

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


void adauga(int x)
{
    if(!cauta(x))
        L[x % cheie].push_back(x);
}


void sterge(int x)
{
    if(cauta(x))
    {
        int j = x % cheie;
        for(int i = 0; i < L[j].size(); i++)
            if (L[j][i] == x)
                 { L[j][i] = L[j][L[j].size() - 1];
                   L[j].pop_back();
                   break;
                 }
    }
}


void citire()
{
    int n, x, y;
    fin >> n;
    for(short i = 1; i <= n; i++)
    {
        fin >> x >> y;
        if(x == 1)
            adauga(y);
        if (x == 2)
            sterge(y);
        if(x == 3)
            fout << cauta(y) << "\n";
    }
}


int main()
{
    citire();
    return 0;
}