Cod sursa(job #1915829)

Utilizator tidehyonBosoi Bogdan tidehyon Data 8 martie 2017 22:40:25
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

#define cheie 66013

vector <int> V[cheie];

int n;
short op;

void Citire()
{
    fin >> n;
}

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

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

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

int main()
{
    Citire();
    int x;
    for(int j = 1; j <= n; j++)
    {
        fin >> op >> x;
        if(op == 1)
            adauga(x);
        else if(op == 2)
            sterge(x);
        else if(op == 3)
            fout << cauta(x) << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}