Cod sursa(job #2549286)

Utilizator Bogdy_PPrunescu Bogdan Bogdy_P Data 17 februarie 2020 15:33:44
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.09 kb
#include <bits/stdc++.h>
#define MOD 666013
using namespace std;

ifstream in("hashuri.in");
ofstream out("hashuri.out");

vector <int> S[MOD];
vector <int>::iterator find_value(int x)
{
    int list = x % MOD;
    vector <int>::iterator it;
    for(it = S[list].begin();it != S[list].end();it++)
    {
        if(*it == x)
            return it;
    }
    return S[list].end();
}
void insert_value(int x)
{
    int list = x % MOD;
    if(find_value(x) == S[list].end())
        S[list].push_back(x);
}
void erase_value(int x)
{
    int list = x % MOD;
    vector <int>::iterator it = find_value(x);
    if(it != S[list].end())
        S[list].erase(it);
}
int n, q, x, y;

int main()
{
    in >> n;
    while(n--)
    {
        in >> q;
        if(q == 1)
        {
            in >> x;
            insert_value(x);
        }
        else if(q == 3)
        {
            in >> x;
            out << (find_value(x) != S[x % MOD].end()) << '\n';
        }
        else
        {
            in >> x;
            erase_value(x);
        }
    }
    return 0;
}