Cod sursa(job #1180014)

Utilizator andrei_toaderToader Andrei Sorin andrei_toader Data 29 aprilie 2014 19:43:36
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <fstream>
#include <vector>

using namespace std;

vector <int> v[666013];

vector<int>::iterator find(int x)
{
    int rest=x%666013;
    for (vector<int>::iterator it=v[rest].begin(); it!=v[rest].end(); ++it)
        if (*it==x)
            return it;
    return v[rest].end();
}

void add(int x)
{
    int rest=x % 666013;
    if (find(x)==v[rest].end())
    {
        v[rest].push_back(x);
    }
}

void remove(int x)
{
    int rest=x%666013;
    vector<int>::iterator it=find(x);
    if (it!=v[rest].end())
        v[rest].erase(it);
}

int main()
{
    int n;
    int type;
    int x;
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    f>>n;
    for (int i=1; i<=n; ++i)
    {
        f>>type>>x;
        if (type==1)
        {
            add(x);
        }
        else
        if (type==2)
        {
            remove(x);
        }
        else
        {
            int rest=x%666013;
            int r=find(x)==v[rest].end()?0:1;
            g<<r<<"\n";
        }
    }
    return 0;
}