Cod sursa(job #1253133)

Utilizator PTAdrian64Pop-Tifrea Adrian PTAdrian64 Data 31 octombrie 2014 20:25:53
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.26 kb
#include <cstdio>
#include <list>
#define n_max 1000010
#define ll long long
#define hash_value 0.618034
#include <math.h>
using namespace std;

ll n;
list < ll > lst[n_max];

inline ll hash_u(ll x){

  //return n*modf(x*hash_value,(double*)&x);
  return x%101;
}

list <ll> :: iterator search_u(ll x){
    ll ind;
    ind = hash_u(x);

   for(list <ll> :: iterator it = lst[ind].begin() ; it != lst[ind].end() ; ++it ){
       if((*it) == x){
          return it;
       }
   }
   return lst[ind].end();
}

int main(void)
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    ll y,ind;
    int x;
    list < ll > :: iterator it;

    scanf("%lld ",&n );
    while(n--){
         scanf("%d %lld ",&x ,&y );
         ind = hash_u(y);
         it = search_u(y);
         switch(x){
            case 1:
               if(it == lst[ind].end())
                 lst[ind].push_front(y);
               break;

            case 2:

               if(it != lst[ind].end())
                 lst[ind].erase(it);
               break;

            case 3:
                if(it != lst[ind].end())
                    printf("1\n");
                else
                    printf("0\n");
         }
    }
}