Cod sursa(job #1838728)

Utilizator BLz0rDospra Cristian BLz0r Data 1 ianuarie 2017 17:18:34
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.09 kb
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

#define MOD 666013

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

vector <int> Hash[MOD + 1];
int poz;

inline int Key(int x) {

    return x % MOD;
}

int Exist(int x) {

    vector <int> :: iterator it;

    int aux = Key(x);

    for (it = Hash[aux].begin(); it < Hash[aux].end(); ++it)
        if (*it == x)
            return it - Hash[aux].begin();

    return -1;
}

void Insert(int x) {

    Hash[Key(x)].push_back(x);
}

void Delete(int x) {

    int aux = Key(x);

    Hash[aux].erase(Hash[aux].begin() + poz);
}

int main() {

    int N;

    fin >> N;

    for (int i = 1; i <= N; ++i) {

        int type, x;
        fin >> type >> x;

        int poz = Exist(x);

        if (type == 1 && poz == -1) {
            Insert(x);
            continue;
        }
        if (type == 2 && poz != -1) {
            Delete(x);
            continue;
        }
       if (type == 3)
            fout << (poz == -1 ? 0 : 1) << "\n";
    }

    return 0;
}