Cod sursa(job #316070)

Utilizator klamathixMihai Calancea klamathix Data 18 mai 2009 11:05:05
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include<cstdio>
#include<vector>

#define DIV 9001
#define MOD 666013
#define MAXN 1 << 20

using namespace std;

inline int Hash( int x) {
       return ( ((x / DIV) + 1) << 5) % MOD;
       }

int i , j , N , type , ok , arg;
vector <int> H[MOD];

int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    
    scanf("%d ",&N);
    
    for( ; N -- ; )
    {
         scanf("%d %d",&type, &arg);
         
         if( type == 1)
         H[Hash(arg)].push_back(arg);
         
         else if(type == 2)
         {
         for( j = 0 ; j < H[Hash(arg)].size() ;j++)
              if( H[Hash(arg)][j] == arg ) H[Hash(arg)][j] = - 1;
         }
         
         else if(type == 3)
         {
              ok = 0;
              for( j = 0 ; j < H[Hash(arg)].size();j++)
                   if(H[Hash(arg)][j] == arg)  ok = 1;
              
              printf("%d\n",ok);
         }
    
    }

return 0;
}