Cod sursa(job #1603354)

Utilizator tudortarniceruTudor Tarniceru tudortarniceru Data 17 februarie 2016 13:55:47
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.22 kb
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;

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

const int MOD = 579107;
vector<int> h[MOD];
inline void Insert(const int x) {
    const int line = x % MOD;
    for (unsigned int i = 0; i < h[line].size(); ++i) {
        if (h[line][i] == x) {
            return;
        }
    }
    h[line].push_back(x);
}
inline void Delete(const int x) {
    const int line = x % MOD;
    for (unsigned int i = 0; i < h[line].size(); ++i) {
        if (h[line][i] == x) {
            swap(h[line][i], h[line][h[line].size() - 1]);
            h[line].pop_back();
        }
    }
}
inline bool Check(const int x) {
    const int line = x % MOD;
    for (unsigned int i = 0; i < h[line].size(); ++i) {
        if (h[line][i] == x) {
            return 1;
        }
    }
    return 0;
}

int n;

int main() {
    fin >> n;
    for (int i = 1;i <= n; ++i) {
        int a, b;
        fin >> a >> b;
        if (a == 1) {
            Insert(b);
        }
        else if (a == 2) {
            Delete(b);
        }
        else {
            fout << Check(b) << '\n';
        }
    }
    fout.close();
    return 0;
}