Cod sursa(job #2594791)

Utilizator bogdan2604Bogdan Dumitrescu bogdan2604 Data 6 aprilie 2020 17:04:38
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.13 kb
#include <bits/stdc++.h>
#define mod 106453

using namespace std;

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

class Hashi
{
public:
    int a;
    list<int> Hash[mod];
    bool exists(int x);
    void insertt(int x);
    void deletee(int x);
};
bool Hashi::exists(int x)
{
    a = x % mod;
    for(auto i = Hash[a].begin(); i != Hash[a].end(); ++ i)
        if(*i == x)
            return 1;
    return 0;
}
void Hashi::insertt(int x)
{
    if(exists(x))
        return ;
    a = x % mod;
    Hash[a].push_back(x);
}
void Hashi::deletee(int x)
{
    a = x % mod;
    for(auto i = Hash[a].begin(); i != Hash[a].end(); ++ i)
        if(*i == x)
        {
            Hash[a].erase(i);
            break;
        }
}

int main()
{
 /*   ios_base::sync_with_stdio(0);
    cin.tie(0);*/
    Hashi obj;
    int n,op,x;
    f >> n;
    for(int i = 1; i <= n; ++ i)
    {
        f >> op >> x;
        switch (op)
        {
            case 1:   obj.insertt(x); break;
            case 2:   obj.deletee(x); break;
            default: g << obj.exists(x) << '\n'; break;
        }
    }
}