Cod sursa(job #2205474)

Utilizator FodosagSera Victor Fodosag Data 19 mai 2018 11:36:16
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#include <iostream>
#include <vector>
#include <fstream>
#define mod 666013

using namespace std;

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

vector <int> V[mod];

int operations;

int H(int x)
{
    return x % mod;
}

vector<int>::iterator findVal(int x)
{
    vector <int>::iterator it;
    int ind = H(x);
    for (it = V[ind].begin(); it != V[ind].end(); ++it)
        if (*it == x)
            return it;
    return V[ind].end();
}

void add(int key)
{
    int ind = H(key);
    if (findVal(key) == V[ind].end())
        V[ind].push_back(key);
}

void del(int key)
{
    int ind = H(key);
    vector<int>::iterator it = findVal(key);
    if (it != V[ind].end())
        V[ind].erase(it);
}

int main()
{
    f>>operations;
    int op, key;
    for (int i = 0; i < operations; ++i)
    {
        f>>op>>key;
        if (op == 1)
        {
            add(key);
            continue;
        }
        if (op == 2)
        {
            del(key);
            continue;
        }
        cout<<(findVal(key) != V[key % mod].end())<<endl;
    }
    return 0;
}