Cod sursa(job #1253152)

Utilizator PTAdrian64Pop-Tifrea Adrian PTAdrian64 Data 31 octombrie 2014 20:39:50
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <cstdio>
#include <list>
#define ll long long

using namespace std;

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

inline ll hash_u(ll x){


  return x%65535;
}

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");
    }
}