Cod sursa(job #2350602)

Utilizator OctavianVasileVasileOctavian OctavianVasile Data 21 februarie 2019 16:00:31
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
const int MOD = 100003;
int n, type, nr, poz, ValH;
vector <int> Hash [MOD + 5];
int Find (int A){
    int ValH = A % MOD;
    for (int i = 0; i < Hash [ValH].size (); i ++)
        if (Hash [ValH][i] == A)return i;
    return -1;
}
void Insert (int A){
    if (Find (A) == -1){
        int ValH = A % MOD;
        Hash [ValH].push_back (A);
    }
}
void Erase (int A){
    poz = Find (A);
    if (poz != -1){
        int ValH = A % MOD;
        Hash [ValH].erase (Hash [ValH].begin () + poz);
    }
}
int main (){
    fin >> n;
    for (int i = 1; i <= n; i ++){
        fin >> type >> nr;
        if (type == 1)Insert (nr);
        else if (type == 2)Erase (nr);
        else if (type == 3){
            if (Find (nr) == -1)fout << "0" << '\n';
            else fout << "1" << '\n';
        }
    }
    return 0;
}