Cod sursa(job #402022)

Utilizator freak93Adrian Budau freak93 Data 23 februarie 2010 12:35:32
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.45 kb
#include<fstream>
#include<list>
#include<vector>
#include<algorithm>

using namespace std;

const char iname[]="hashuri.in";
const char oname[]="hashuri.out";

ifstream f(iname);
ofstream g(oname);

class hash
{
    public:
    int mod;
    vector<list<pair<int,int> > > c;
    hash()
    {
        mod=679227;
        c.resize(mod);
    }
    hash(int x)
    {
        mod=x;
        c.resize(mod);
    }

    list<pair<int,int> >::iterator find(int x)
    {
        int y=x%mod;
        for(list<pair<int,int> >::iterator it=c[y].begin();it!=c[y].end();++it)
            if(it->first==x)
                return it;
        return c[0].end();
    }

    void update(int x,int s)
    {
        int y=x%mod;
        list<pair<int,int> >::iterator it=find(x);
        if(it==c[0].end())
            c[y].push_back(make_pair(x,s));
        else
            it->second+=s;

    }

    void erase(int x)
    {
        int y=x%mod;
        list<pair<int,int> >::iterator it=find(x);
        if(it!=c[0].end())
            c[y].erase(it);
    }
} H(163841);

int n,x,y,i;

int main()
{
    f>>n;
    for(i=1;i<=n;++i)
    {
        f>>x>>y;
        if(x==1)
            H.update(y,1);
        if(x==2)
            H.erase(y);
        if(x==3)
            if(H.find(y)!=H.c[0].end())
                g<<"1\n";
            else
                g<<"0\n";
    }

    f.close();
    g.close();

    return 0;
}