Cod sursa(job #2373247)

Utilizator Groza_Iulia_DianaGroza Iulia Diana Groza_Iulia_Diana Data 7 martie 2019 12:50:28
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

int n, x, y;
const int p=666013;

vector<int> h[p];

vector<int>::iterator find_value(int x)
{
    vector<int>::iterator it;
    for(it=h[x%p].begin(); it!=h[x%p].end(); it++)
        if(*it==x)
            return it;
    return h[x%p].end();
}

void insert_value(int x)
{
    if(find_value(x)==h[x%p].end())
        h[x%p].push_back(x);
}

void erase_value(int x)
{
    if(find_value(x)!=h[x%p].end())
        h[x%p].erase(find_value(x));
}

int main()
{
    fin >> n;
    while(n--)
    {
        fin >> x >> y;
        if(x==1)
            insert_value(y);
        if(x==2)
            erase_value(y);
        if(x==3)
            fout << (find_value(y)!=h[y%p].end()) << "\n";
    }
    return 0;
}