Cod sursa(job #1564598)

Utilizator sulzandreiandrei sulzandrei Data 9 ianuarie 2016 19:53:15
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
#define ll long long int
#define pb push_back
ifstream in ("hashuri.in");
ofstream out("hashuri.out");
const int nr_prim  = 195931;
vector<ll> v[nr_prim];
ll modulo(int nr )
{
    return nr % nr_prim;
}

void add(ll e)
{
    if ( find(v[ modulo(e) ].begin(),v[modulo(e)].end(),e) != v[ modulo(e)].end())
        return;
    v[ modulo(e)].pb(e);
}
void erase(ll e)
{
    if (find(v[ modulo(e) ].begin(),v[modulo(e)].end(),e) != v[ modulo(e)].end())
        v[ modulo(e)].erase(find(v[ modulo(e) ].begin(),v[modulo(e)].end(),e));
}
int find(ll e)
{
    if (find(v[ modulo(e) ].begin(),v[modulo(e)].end(),e) !=v[modulo(e)].end())
        return 1;
    return 0;
}
int main()
{
    ll n,x,op;
    in >> n;
    for(int i = 0 ; i < n ; i ++)
    {
        in >> op >> x;
        switch(op)
        {
            case 1: add(x); break;
            case 2: erase(x); break;
            case 3: out<<find(x)<<'\n' ; break;
        }
    }
    return 0;
}