Cod sursa(job #529062)

Utilizator gabipurcaruGabi Purcaru gabipurcaru Data 4 februarie 2011 09:40:18
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.88 kb
// infoarena: problema/hashuri //
#include <fstream>
#include <set>
using namespace std;

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

const int MAXN = 1000010;
const int HASH_PRIME = 666013;

template<typename T>
struct hash
{
    multiset<T> h[HASH_PRIME];
    void push(T val)
    {
        h[val%HASH_PRIME].insert(val);
    }
    void pop(T val)
    {
        typeof(h[0].end()) it = h[val%HASH_PRIME].find(val);
        if(it == h[val%HASH_PRIME].end())
            return;
        h[val%HASH_PRIME].erase(it);
    }
    bool find(T val)
    {
        return h[val%HASH_PRIME].find(val) != h[val%HASH_PRIME].end();
    }
};

hash<int> h;
int n,a,b,i;

int main()
{
    in>>n;
    for(i=1; i<=n; i++)
    {
        in>>a>>b;
        if(a == 1)
            h.push(b);
        else if(a == 2)
            h.pop(b);
        else
            out<<h.find(b)<<'\n';
    }

    return 0;
}