Cod sursa(job #1863138)

Utilizator rebound212Mihnea Savu rebound212 Data 30 ianuarie 2017 19:01:27
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.28 kb
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <cstdio>
#include <climits>

#define PII pair < int , int >
#define MP make_pair
#define PB push_back

using namespace std;
vector <int> H[666013];
vector <int> :: iterator it;
int n,op,val;

int calculateKey (int val)
{
  return val%666013;
}

void insertValue(int val)
{
  int key = calculateKey(val);
  H[key].PB(val);
}

void deleteValue(int val)
{
   int key = calculateKey(val);
   for(it = H[key].begin(); it!=H[key].end(); it++)
   {
      if (*it == val)
        {H[key].erase(it); break;}
   }
}

int checkValue(int val)
{
    int key = calculateKey(val);
    for(it = H[key].begin(); it!=H[key].end(); it++)

      if (*it == val) return 1;
    return 0;
}

int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%d",&n);
    for (int i=1 ; i<=n ; ++i)
    {
       scanf("%d %d",&op,&val);
       switch(op)
       {
           case 1: insertValue(val); break;
           case 2: deleteValue(val); break;
           case 3: printf("%d\n",checkValue(val)); break;
       }
    }

    return 0;
}