Cod sursa(job #1604665)

Utilizator tudormaximTudor Maxim tudormaxim Data 18 februarie 2016 14:26:25
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");

const int mod = 666013;
vector <int> h[mod];
int poz;

inline void Add(const int &x)
{
    vector <int> :: iterator it;
    for(it=h[poz].begin(); it!=h[poz].end(); it++)
        if(*it==x) return;
    h[poz].push_back(x);
}

inline void Delete(const int &x)
{
    vector <int> :: iterator it;
    for(it=h[poz].begin(); it!=h[poz].end(); it++)
        if(*it==x)
        {
            h[poz].erase(it);
            return;
        }
}

inline bool Exist(const int &x)
{
    vector <int> :: iterator it;
    for(it=h[poz].begin(); it!=h[poz].end(); it++)
        if(*it==x) return true;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n, op, i, x, poz;
    fin >> n;
    for(i=1; i<=n; i++)
    {
        fin >> op >> x;
        poz=x%mod;
        if(op==1) Add(x);
        if(op==2) Delete(x);
        if(op==3) fout << Exist(x) << "\n";
    }
    fin.close();
    fout.close();
    return 0;
}