Cod sursa(job #1880640)

Utilizator giotoPopescu Ioan gioto Data 15 februarie 2017 20:49:39
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.07 kb
#include <cstdio>
#include <vector>
#define MOD 666013
using namespace std;

int n;
vector <int> Hash[MOD + 1];
inline void add_Hash(int x){
    int L = x % MOD;
    vector<int> :: iterator it;
    for(it = Hash[L].begin() ; it != Hash[L].end() ; ++it)
    if(*it == x) return ;
    Hash[L].push_back(x);
}
inline void delete_Hash(int x){
    int L = x % MOD;
    vector<int> :: iterator it;
    for(it = Hash[L].begin() ; it != Hash[L].end() ; ++it)
    if(*it == x) {Hash[L].erase(it); return ;}
}
inline void check_Hash(int x){
    int L = x % MOD;
    vector<int> :: iterator it ;
    for(it = Hash[L].begin() ; it != Hash[L].end() ; ++it)
        if(*it == x) {printf("1\n"); return ;}
    printf("0\n");

}
int main()
{
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    scanf("%d", &n);
    for(int i = 1; i <= n ; ++i){
        int tip , x;
        scanf("%d%d", &tip, &x);
        if(tip == 1)add_Hash(x);
        else if(tip == 2) delete_Hash(x);
        else if(tip == 3) check_Hash(x);
    }
    return 0;
}