Cod sursa(job #1648325)

Utilizator paunmatei7FMI Paun Matei paunmatei7 Data 11 martie 2016 09:31:23
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.13 kb
#include <fstream>
#include <vector>

#define Mod 666013

using namespace std;

ifstream cin("hashuri.in");
ofstream cout("hashuri.out");

vector < int > Hash[Mod];
int n;

void insert(int x){
    int ok = 0;
    for(vector < int > :: iterator it = Hash[x % Mod].begin(); it != Hash[x % Mod].end() && ok == 0; ++it)
        if(*it == x)
            ok = 1;
    if(ok == 0)
        Hash[x % Mod].push_back(x);
}

void erase(int x){
    int ok = 0;
    for(vector < int > :: iterator it = Hash[x % Mod].begin(); it != Hash[x % Mod].end() && ok == 0; ++it)
        if(*it == x){
            ok = 1;
            *it = -1;
        }
}

int find(int x){
    int ok = 0;
    for(vector < int > :: iterator it = Hash[x % Mod].begin(); it != Hash[x % Mod].end() && ok == 0; ++it)
        if(*it == x)
            ok = 1;
    return ok;
}

int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        int Type, x;
        cin >> Type >> x;
        if(Type == 1)
            insert(x);
        if(Type == 2)
            erase(x);
        if(Type == 3)
            cout << find(x) << "\n";
    }
    return 0;
}