Cod sursa(job #978632)

Utilizator crisbodnarCristian Bodnar crisbodnar Data 29 iulie 2013 12:32:44
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#define u unsigned
#define key a[poz][i]

using namespace std;

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

const int mod = 666013;
vector <int> a[mod+1];

void Erase(const int x)
{
    const int poz = x % mod, m = a[poz].size()-1;
    for(u i=0; i<a[poz].size(); i++)
        if(key == x)
        {
            swap(key, a[poz][m]);
            a[poz].pop_back();
            break;
        }
}

bool Find(const int x)
{
    const int poz = x % mod;
    for(u i=0; i<a[poz].size(); i++)
         if(key == x) return 1;
    return 0;
}

void Insert(const int x)
{
    if(Find(x)) return;
    const int poz = x % mod;
    a[poz].push_back(x);
}

int main()
{
    int n; fin>>n;
    while(n--)
    {
        int op, x;
        fin>>op>>x;
        if(op == 1) Insert(x); else
        if(op == 2) Erase(x);  else
        fout<<Find(x)<<'\n';
    }
    return 0;
}