Cod sursa(job #1527612)

Utilizator Vele_GeorgeVele George Vele_George Data 18 noiembrie 2015 14:27:34
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <vector>
#include <fstream>
#define int2 long long
#define hash 100000000
using namespace std;

vector<int2> table[hash+1];
int j;
bool found(int2 x)
{
    int p = x % hash;
    for(int i=0; i<table[p].size(); i++)
        if (table[p][i] == x) { j=i; return 1;}
    return 0;
}

void ins(int2 x)
{
    int p = x % hash;
    if (!found(x))
        table[p].push_back(x);
    return;
}

void del(int2 x)
{
    int p = x % hash;
    if (found(x))
        table[p].erase(table[p].begin()+j);
    return;
}

int main()
{
    ifstream f("hashuri.in");
    ofstream g("hashuri.out");
    int2 val, act, n;
    f >> n;
    for(int i=1; i<=n; i++)
    {
        f >> act >> val;
        if (act == 1) ins(val);
        else
        if (act == 2) del(val);
        else g << found(val) << "\n";
    }

    f.close();
    g.close();
    return 0;
}