Cod sursa(job #1572457)

Utilizator cernat.catallinFMI Cernat Catalin Stefan cernat.catallin Data 18 ianuarie 2016 22:16:24
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <stdio.h>
#include <list>
#include <vector>
#include <math.h>
using namespace std;
 
vector < list<int> > hash;
list <int>::iterator it;
 
float A;
int m, n, op, nr;
 
inline int hashing(int x){
    return (x % m);
}
 
inline void add(int x){
    hash[ hashing(x) ].push_back(x);
}
 
inline void del(int x){
    for(it = hash[ hashing(x) ].begin(); it != hash[ hashing(x) ].end(); ++it)
        if(*it == x){
            hash[ hashing(x) ].erase(it);
            return;
        }
}
 
inline int search(int x){
    for(it = hash[ hashing(x) ].begin(); it != hash[ hashing(x) ].end(); ++it)
        if(*it == x) return 1;
    return 0;
}
 
void solve(){
    A = (sqrt(5) - 1)/2;
    m = 666013;
 
    scanf("%i", &n);
    hash.resize(m+3);
 
    for(int i = 1; i <= n; ++i){
        scanf("%i %i", &op, &nr);
 
        if(op == 1) add(nr);
        else if (op == 2) del(nr);
        else printf("%i\n", search(nr));
    }
}
 
int main(){
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
 
    solve();
 
    fclose(stdin);
    fclose(stdout);
 
    return 0;
}