Cod sursa(job #2040931)

Utilizator Andrei_Info1Ionescu Andrei Andrei_Info1 Data 16 octombrie 2017 18:05:01
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int M=666013;
vector <int> G[M+5];

vector <int>::iterator it;
//it=find(v.begin() , v.end() , x);
int h(int key)
{
    return key%M;
}
int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    int i, N, op, x, hs;
    scanf("%d", &N);
    for(i=1 ; i<=N ; i++)
    {
        scanf("%d%d", &op, &x);
        hs = h(x);
        if(op==1)
            G[hs].push_back(x);
        else if(op==2)
        {
            it=find(G[hs].begin() , G[hs].end() , x);
            if(it != G[hs].end())
                G[hs].erase(it);
        }
        else
        {
            it=find(G[hs].begin() , G[hs].end() , x);
            if(it != G[hs].end())
                printf("1\n");
            else
                printf("0\n");
        }
    }
    return 0;
}