Cod sursa(job #1446106)

Utilizator dm1sevenDan Marius dm1seven Data 31 mai 2015 21:11:34
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.55 kb
/*
 * e_030_hashuri.cpp
 *
 *  Created on: May 31, 2015
 *      Author: Marius
 */

#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
using namespace std;

namespace e_030_hashuri_nms
{
    int N, n, m1, m2;
    vector<set<int>> hash_set;
    //map<int, set<int>> hash_map_set;
    
    inline int hash_func1(int x)
    {
        return x % m1;
    }
    
    inline int hash_func2(int x)
    {
        int xm1 = x % m1;
        return xm1 * m2 + xm1%m2;
    }
    
    inline int hash_size1() 
    {
        return m1;
    }
    
    inline int hash_size2()
    {
        return m1 * m2;
    }
}

int main()
{
    using namespace e_030_hashuri_nms;
    
    ifstream ifs("hashuri.in");
    ofstream ofs("hashuri.out");
    
    ifs >> N;
    n = 2000000000;
    m1 = 1 << 21;
    m2 = 1 << 6;
    
    int sz = hash_size1();
    hash_set.resize(sz);
    
    for (int i = 1; i <= N; i++)
    {
        int op, x;
        ifs >> op >> x;
        int pos = hash_func1(x); //the position in the hash_set
        switch (op)
        {
        case 1:
            hash_set[pos].insert(x);
            break;
        case 2:
            hash_set[pos].erase(x);
            break;
        default:
            set<int>::iterator it = hash_set[pos].find(x);
            int in_set = 0;
            if (it != hash_set[pos].end()) in_set = 1;
            ofs << in_set << '\n';
        }
    }
    
    ifs.close();
    ofs.close();
    
    return 0;
}