Cod sursa(job #1210411)

Utilizator daniel.amarieiDaniel Amariei daniel.amariei Data 19 iulie 2014 22:24:08
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <set>
#define M 666013
#define H(x) (x % M)
using namespace std;

set<int>* S[M];

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

int main()
{
    int n;
    
    ifs >> n;
    for (int i = 1; i <= n; ++i)    
    {
        int op, x;
        ifs >> op >> x;

        // Determine the bucket
        int hx = H(x);
        if (S[hx] == NULL)
        {
            S[hx] = new set<int>;
        }
        
        set<int>* bucket = S[hx];
        set<int>::iterator it = bucket->find(x);
        
        switch(op)
        {
            case 1:
                bucket->insert(x);
                
                break;
            
            case 2: 
                bucket->erase(x);
                
                break;
            
            case 3:
                ofs << (it == bucket->end() ? 0 : 1) << "\n";
                break;
        }
    }
    
    return 0;
}