Cod sursa(job #2426663)

Utilizator PopescuAndreiAlexandruPopescu Andrei Alexandru PopescuAndreiAlexandru Data 28 mai 2019 23:27:06
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.25 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

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

#define Nmode 15777

int n,task,x;

vector <int> v[Nmode];

int Find(int x)
{
    int l=x%Nmode,ok=0;
    vector <int> ::iterator it;
    for(it=v[l].begin();it!=v[l].end();it++)
    {
        if(*it==x)
        {
            ok=1;
            break;
        }
    }
    return ok;
}

void Insert(int x)
{
    int l=x%Nmode;
    if(!Find(x))
        v[l].push_back(x);
}

void Erase(int x)
{
    int l=x%Nmode;
    vector <int> ::iterator it;
    for(it=v[l].begin();it!=v[l].end();it++)
    {
        if(*it==x)
        {
            v[l].erase(it);
            break;
        }
    }
}

int main()
{
    fin>>n;
    for(int i=1;i<=n;i++)
    {
        fin>>task>>x;
        switch(task)
        {
        case 1:
            {
                if(!Find(x))
                    Insert(x);
                break;
            }
        case 2:
            {
                Erase(x);
                break;
            }
        case 3:
            {
                fout<<Find(x)<<'\n';
                break;
            }
        }
    }
}