Cod sursa(job #2626143)

Utilizator UrsaWarlordFrincu Madalin Gabriel UrsaWarlord Data 6 iunie 2020 12:08:49
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.06 kb
#include <bits/stdc++.h>
#define MOD 642643
using namespace std;
int N,i,j,op,x;


vector<int> vect[MOD];

vector<int>::iterator find_val(int x)
{
    int hashed = x%MOD;
    for(auto it = vect[hashed].begin(); it != vect[hashed].end(); ++it)
        if(*it == x)
            return it;
    return vect[hashed].end();
}

void insert_val(int x)
{
    int hashed = x % MOD;
    if(find_val(x) == vect[hashed].end())
        vect[hashed].push_back(x);
}
void erase_val(int x)
{
    int hashed = x % MOD;
    auto it = find_val(x);
    if (it  != vect[hashed].end())
        vect[hashed].erase(it);
}
int main()
{
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    f>>N;
    for(i=0;i<N;i++)
    {
        f>>op>>x;
        switch(op)
        {
        case 1:
            insert_val(x);
            break;
        case 2:
            erase_val(x);
            break;
        case 3:
            g<< (find_val(x) != vect[x%MOD].end()) << "\n";
            break;
        }
    }
    f.close();
    g.close();
    return 0;
}