Cod sursa(job #2038149)

Utilizator cyg_vladioanBirsan Vlad cyg_vladioan Data 13 octombrie 2017 12:16:39
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
const int M = 666013;
set <int> s[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);
            s[a].insert(x);
        }
        else if(op == 2)
        {
            a = h(x);
            set<int>::iterator it;
            it = find(s[a].begin() , s[a].end() , x);
            if(it != s[a].end())
                s[a].erase(it);
        }
        else if(op == 3)
        {
            set <int>::iterator it;
            a = h(x);
            it = s[a].find(x);
            if(it != s[a].end())
                printf("1\n");
            else
                printf("0\n");
        }
    }
    return 0;
}