Cod sursa(job #2143269)

Utilizator AndreiTurcasTurcas Andrei AndreiTurcas Data 25 februarie 2018 19:17:02
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <iostream>
#include <fstream>
#include <vector>
#define in vector<int>::iterator
using namespace std;

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

const int M = 666013;
vector<int> H[M];
int n;

in Find(int x)
{
    int l = x % M;
    for(in it = H[l].begin(); it != H[l].end(); ++it)
        if(*it == x)
        return it;
    return H[l].end();
}

void Insert(int x)
{
    int l = x % M;
    if(Find(x) == H[l].end())
        H[l].push_back(x);
}

void Delete(int x)
{
    int l = x % M;
    in it = Find(x);
    if(it != H[l].end())
        H[l].erase(it);
}

int main()
{
    int k, val;
    f >> n;
    for(int i = 1; i <= n; ++i)
    {
        f >> k >> val;
        if(k == 1) Insert(val);
        else if(k == 2) Delete(val);
        else g << (Find(val) != H[val%M].end()) << "\n";
    }
}