Cod sursa(job #1830084)

Utilizator MithrilBratu Andrei Mithril Data 16 decembrie 2016 09:31:18
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int PRIME = 12289;
const int R = rand()%4200;
vector<int> hashTable[PRIME];
int n,x,y,pos;

inline int h(int x){return ((x*R)%PRIME);}

int main()
{
    fin>>n;
    for(int i=1;i<=n;i+=1)
    {
        fin>>x>>y;
        pos=h(y);
        auto getPosition = find(hashTable[pos].begin(),hashTable[pos].end(),y);
        switch(x)
        {
        case 1:
            if(getPosition==hashTable[pos].end())
                hashTable[pos].push_back(y);
            break;
        case 2:
            if(getPosition!=hashTable[pos].end())
                hashTable[pos].erase(getPosition);
            break;
        case 3:
            fout<<(getPosition!=hashTable[pos].end())<<'\n';
            break;
        }
    }
    return 0;
}