Cod sursa(job #1259077)

Utilizator PTAdrian64Pop-Tifrea Adrian PTAdrian64 Data 9 noiembrie 2014 18:02:46
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.09 kb
#include <cstdio>
#include <list>
#define ll long long
#define n_max_value 262143

using namespace std;

ll n;
list < ll > lst[n_max_value];
list <ll> :: iterator it;

inline ll hash_u(ll x){


  return x%n_max_value;
}

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

   for( 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;

    scanf("%lld ",&n );
    while(n--){
         scanf("%d %lld ",&x ,&y );
         ind = hash_u(y);
         it = search_u(y);
         if(x==1){
             if(it == lst[ind].end())
                 lst[ind].push_back(y);
             continue;
         }
         if(x==2){
             if(it != lst[ind].end())
                 lst[ind].erase(it);
             continue;
         }
         if(it == lst[ind].end())
            printf("0\n");
         else
            printf("1\n");
    }
}