Cod sursa(job #1235792)

Utilizator hopingsteamMatraguna Mihai-Alexandru hopingsteam Data 30 septembrie 2014 18:12:12
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.09 kb
#include    <fstream>
#include    <vector>
const int MOD=666013;

using namespace std;

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

vector < int > V[MOD];

int N;

vector <int> :: iterator find(int Value)
{
    int List=Value%MOD;
    
    for(vector <int> :: iterator it = V[List].begin();it!=V[List].end();it++)
        if(*it == Value)
            return it;
    return V[List].end();
}

void Insert(int Value)
{
    int List=Value%MOD;
    if (find(Value)==V[List].end())
        V[List].push_back(Value);
}

void Delete(int Value)
{
    int List=Value%MOD;
    vector <int> :: iterator it = find(Value);
    if (it!=V[List].end())
        V[List].erase(it);
}

void read()
{
    int op, x;
    fin >> N;
    for(int i = 1; i <= N; i++)
    {
        fin >> op >> x;
        if(op == 1)
        {
            Insert(x);
        }
        if(op == 2)
        {
            Delete(x);
        }
        if(op == 3)
        {
            fout<< (find(x)!=V[x%MOD].end()) <<'\n';
        }
    }
}

int main()
{
    read();
    return 0;
}