Cod sursa(job #1119962)

Utilizator BonCipBonciocat Ciprian Mircea BonCip Data 24 februarie 2014 20:58:30
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.94 kb
#include <stdio.h>
#include <set>
using namespace std;

#define N_MAX 1000000
#define modP 150001
#define mulQ 20011

set< int > htable[ modP ];

int hash( long long x ) {
    return ( x * mulQ ) % modP;
}

void add( long long x ) {
    int h = hash( x );
    htable[ h ].insert( x );
}

void rem( long long x ) {
    int h = hash( x );
    htable[ h ].erase( x );
}

int ask( long long x ) {
    int h = hash( x );
    return htable[ h ].count( x ) == 1;
}

int main( ) {
    FILE * fin, * fout;
    fin = fopen( "hashuri.in", "r" );
    fout = fopen( "hashuri.out", "w" );

    int N;
    fscanf( fin, "%d", &N );

    int i;
    for( i = 1; i <= N; i ++ ) {
        int tp;
        long long x;
        fscanf( fin, "%d%lld", &tp, &x );
        if( tp == 1 ) {
            add( x );
        } else if( tp == 2 ) {
            rem( x );
        } else {
            fprintf( fout, "%d\n", ask( x ) );
        }
    }

    fclose( fin );
    fclose( fout );
}