Cod sursa(job #1279612)

Utilizator diana97Diana Ghinea diana97 Data 30 noiembrie 2014 17:24:17
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.14 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream f ("hashuri.in");
ofstream g ("hashuri.out");

const int MOD = 666013;

vector <int> h[MOD];

inline bool gasit(int valoare) {
    int rest = valoare % MOD;
    vector <int> :: iterator it;
    for (it = h[rest].begin(); it != h[rest].end(); it++)
        if (*it == valoare) return true;
    return false;
}

inline void adauga(int valoare) {
    int rest = valoare % MOD;
    vector <int> :: iterator it;
    for (it = h[rest].begin(); it != h[rest].end(); it++)
        if (*it == -1) {
            *it = valoare;
            return;
        }
    h[rest].push_back(valoare);
}

inline void sterge(int valoare) {
    int rest = valoare % MOD;
    vector <int> :: iterator it;
    for (it = h[rest].begin(); it != h[rest].end(); it++)
        if (*it == valoare) {
            *it = -1;
            return;
        }
}


int main() {
    int n, tip, x;
    f >> n;
    while (n--) {
        f >> tip >> x;
        if (tip == 1) {
            if (!gasit(x)) adauga(x);
        }
        else if (tip == 2) sterge(x);
        else cout << gasit(x) << '\n';
    }
    return 0;
}