Cod sursa(job #2036810)

Utilizator CiprianC111Constantinescu Ciprian CiprianC111 Data 11 octombrie 2017 09:33:40
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <vector>
#include <cstdio>
#include <algorithm>

const int M = 666013;

using namespace std;

vector< vector<int> > v;
vector<int>::iterator it;

int h(int n)
{
    return n % M;
}

int main()
{
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    int n, f, x, a;
    scanf("%d", &n);
    v.resize(M);
    for(int i = 0; i < n; i++)
    {
        scanf("%d%d", &f, &x);
        a = h(x);
        if(f == 1)
        {
            v[a].push_back(x);
        }
        else
        {
            it = find(v[a].begin(), v[a].end(), x);
        }
        if(f == 2)
        {
            if(it != v[a].end())
                v[a].erase(it);
        }
        if(f == 3)
        {
            printf("%d\n", (it != v[a].end()));
        }
    }
    return 0;
}