Cod sursa(job #2106852)

Utilizator chiriacandrei25Chiriac Andrei chiriacandrei25 Data 16 ianuarie 2018 12:38:14
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include <cstdio>
#include <vector>
#define P 100021

using namespace std;

vector <int> H[P];

inline bool Search(int x)
{
    int i=x%P;
    vector <int>::iterator it;
    for(it=H[i].begin();it!=H[i].end();++it)
        if(*it==x)
            return true;
    return false;
}

inline void Add(int x)
{
    int i=x%P;
    H[i].push_back(x);
}

inline void Delete(int x)
{
    int i=x%P;
    vector <int>::iterator it;
    for(it=H[i].begin();it!=H[i].end();++it)
        if(*it==x)
        {
            H[i].erase(it);
            return;
        }
}

int main()
{
    int M,tip,x;
    freopen ("hashuri.in","r",stdin);
    freopen ("hashuri.out","w",stdout);
    scanf("%d", &M);
    while(M--)
    {
        scanf("%d%d", &tip,&x);
        if(tip==1 && !Search(x))
            Add(x);
        if(tip==2 && Search(x))
            Delete(x);
        if(tip==3)
            printf("%d\n", Search(x));
    }
    return 0;
}