Cod sursa(job #2038147)

Utilizator cyg_vladioanBirsan Vlad cyg_vladioan Data 13 octombrie 2017 12:15:55
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.08 kb
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int M = 666013;
vector <int> T[M + 5];
int h(int key)
{
    return key % M;
}
int main()
{
    freopen("hashuri.in" , "r" , stdin);
    freopen("hashuri.out" , "w" , stdout);
    int n , op , x , i , a;
    scanf("%d" , &n);
    for(i = 1 ; i <= n ; i ++)
    {
        scanf("%d%d" , &op , &x);
        if(op == 1)
        {
            a = h(x);
            T[a].push_back(x);
        }
        else if(op == 2)
        {
            vector <int>::iterator it;
            a = h(x);
            it = find(T[a].begin() , T[a].end() , x);
            if(it != T[a].end())
                T[a].erase(it);
            //T[a].erase(find(T[a].begin() , T[a].end() , x));
        }
        else if(op == 3)
        {
            vector <int>::iterator it;
            a = h(x);
            it = find(T[a].begin() , T[a].end() , x);
            if(it != T[a].end())
                printf("1\n");
            else
                printf("0\n");
        }
    }
    return 0;
}