Cod sursa(job #1741123)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 12 august 2016 23:58:11
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include<bits/stdc++.h>
#define VAL 666013
using namespace std;
vector<int> v[VAL+5];
vector<int>::iterator it;
int n,op,x;
void adauga(int x)
{
    int y=x%VAL;
    for(it=v[y].begin();it!=v[y].end();it++)
    {
        if (*it==x) return;
    }
    v[y].push_back(x);
}
void sterge(int x)
{
    int y=x%VAL;
    for(it=v[y].begin();it!=v[y].end();it++)
    {
        if (*it==x)
        {
            v[y].erase(it);
            return;
        }
    }
}
void interogare(int x)
{
    int y=x%VAL;
    for(it=v[y].begin();it!=v[y].end();it++)
    {
        if (*it==x)
        {
            printf("1\n");
            return ;
        }
    }
    printf("0\n");
}
int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&op,&x);
        if (op==1) adauga(x);
            else
        if (op==2) sterge(x);
            else interogare(x);
    }
    return 0;
}