Cod sursa(job #1341614)

Utilizator okros_alexandruOkros Alexandru okros_alexandru Data 12 februarie 2015 22:31:50
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1 kb
#include <fstream>
#include <vector>

#define Nmax 200100
#define mod 666013

using namespace std;

vector <int> V[mod];
int index;

void getIndex(int X) {

    index = X % mod;

}
int search(int X) {

    getIndex(X);

    int m = V[index].size();

    for(int i = 0; i < m; i++)
        if(V[index][i] == X)
            return i;

    return -1;

}
void insert(int X) {

    if(search(X) == -1)
        V[index].push_back(X);

}
void remove(int X) {

    int position;

    if((position = search(X)) != -1)
        V[index].erase(V[index].begin() + position);

}
int main() {

    int type, x, T;

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

    in >> T;

    while(T--) {

        in >> type >> x;

        switch(type) {
            case 1: insert(x); break;
            case 2: remove(x); break;
            case 3: out << (search(x) != -1) << '\n';
            }

        }

    in.close();
    out.close();

    return 0;

}