Cod sursa(job #1053514)

Utilizator uagamagaMatei Rogoz uagamaga Data 12 decembrie 2013 20:02:36
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.03 kb
#include <fstream>
#include <vector>
using namespace std;

#define numberOfZones 666013

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

vector < vector <int> > Hash(numberOfZones+1);

void INS(int value)
{
    int zone = value % numberOfZones,ok=0,i;

    for(i=0;i<Hash[zone].size();i++)
        if(Hash[zone][i] == value)
            ok = 1;

    if(!ok)
        Hash[zone].push_back(value);

}
void DEL(int value)
{
    int zone = value % numberOfZones,i;

    for(i=0;i<Hash[zone].size();i++)
        if(Hash[zone][i]==value)
        {
            Hash[zone][i] = Hash[zone].back();
            Hash[zone].pop_back();
        }

}
int SCH(int value)
{
    int zone = value % numberOfZones,i;

    for(i=0;i<Hash[zone].size();i++)
        if(Hash[zone][i]==value)
            return 1;

    return 0;

}
int main()
{
    int n,op,x;

    in>>n;

    while(n--)
    {
        in>>op>>x;

        if(op==1)
            INS(x);

        if(op==2)
            DEL(x);

        if(op==3)
            out<<SCH(x)<<"\n";

    }

    return 0;
}