Cod sursa(job #911445)

Utilizator TeodoraTanaseTeodora Tanase TeodoraTanase Data 11 martie 2013 18:16:45
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.19 kb
#include <cstdio>
#include <vector>

#define M 99971

using namespace std;

vector < int > H[M];

int y;

bool Search(int ind, int val)
{
    unsigned int m = H[ind].size();

    for(unsigned int i = 0; i < m; ++ i)
        if(H[ind][i] == val)
            return 1;

    return 0;
}

void Add(int x)
{
    if(!Search(y, x))
        H[y].push_back(x);
}

void Delete(int ind, int val)
{
    unsigned int m = H[ind].size();

    for(unsigned int i = 0; i < m; ++ i)
        if(H[ind][i] == val)
        {
            H[ind].erase(H[ind].begin() + i);
            return;
        }
}

void Remove(int x)
{
    if(Search(y, x))
        Delete(y, x);
}

int main()
{
    int n;
    int c;
    int x;

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

    scanf("%d\n", &n);

    while(n --)
    {
        scanf("%d %d\n", &c, &x);
        y = x % M;

        if(c == 1)
            Add(x);
        else
            if(c == 2)
                Remove(x);
            else
                if(Search(y, x))
                    printf("1\n");
                else
                    printf("0\n");
    }

    return 0;
}