Cod sursa(job #2109197)

Utilizator inquisitorAnders inquisitor Data 19 ianuarie 2018 11:56:47
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.95 kb
#include <bits/stdc++.h>

using namespace std;

#define MOD 16383

vector<int> v[16384];

void Delete(int N)
{
    int h = N & MOD;

    for(int i = 0; i != v[h].size(); ++i)
    {
        if(v[h][i] == N)
        {
            v[h][i] = v[h][v[h].size() - 1];

            v[h].pop_back();

            return;
        }
    }
}

bool Find(int N)
{
    int h = N & MOD;

    for(int i = 0; i != v[h].size(); ++i)
    {
        if(v[h][i] == N)
        {
            return true;
        }
    }

    return false;
}

void Insert(int N)
{
    int h = N & MOD;

    v[h].push_back(N);
}

int main()
{
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);

    int T, Q, x;

    for(scanf("%d", &T); T--;)
    {
        scanf("%d %d", &Q, &x);

        if(Q == 1) Insert(x);

        if(Q == 2) Delete(x);

        if(Q == 3) printf("%c\n", '0' + Find(x));
    }

    return 0;
}