Cod sursa(job #1210436)

Utilizator daniel.amarieiDaniel Amariei daniel.amariei Data 19 iulie 2014 23:11:54
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <fstream>
#include <vector>
#include <algorithm>
//#define M 666013
#define M 300007
#define H(x) (x % M)
using namespace std;

vector<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 vector<int>;
        }
        
        vector<int>* bucket = S[hx];
        vector<int>::iterator it = find(bucket->begin(), bucket->end(), x);
        
        switch(op)
        {
            case 1:
                bucket->push_back(x);
                
                break;
            
            case 2: 
                if (it != bucket->end())
                {
                    bucket->erase(it);
                }
                
                break;
            
            case 3:
                ofs << (it == bucket->end() ? 0 : 1) << "\n";
                break;
        }
    }
    
    return 0;
}