Cod sursa(job #2450500)

Utilizator petrisorvmyVamanu Petru Gabriel petrisorvmy Data 23 august 2019 15:41:27
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <fstream>
#include <vector>
#define MOD 666013

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");

vector <int> key[MOD];
int n, q , x;
vector <int> :: iterator find_val(int x)
{
    vector <int> :: iterator it;
    for(it = key[x % MOD].begin(); it != key[x % MOD].end(); ++it)
        if(*it == x)
            return it;
    return key[x % MOD].end();
}
void add(int x)
{
    if(find_val(x) == key[x % MOD].end())
        key[x % MOD].push_back(x);
}
void del(int x)
{
    vector <int> :: iterator it;
    it = find_val(x);
    if(it != key[x % MOD].end())
        key[x % MOD].erase(it);
}
int main()
{
    f >> n;
    while(n--)
    {
        f >> q >> x;
        if(q == 1)
            add(x);
        if(q == 2)
            del(x);
        if(q == 3)
            g << (find_val(x) != key[x % MOD].end() )<< '\n';
    }
    f.close(); g.close();
    return 0;
}