Cod sursa(job #731374)

Utilizator ColcerPColcer Paul ColcerP Data 7 aprilie 2012 22:42:28
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
#include <fstream>
#include <vector>
using namespace std;

#define valoare 700001;

int n;
vector<int>M[valoare];


vector<int>::iterator findValue(int x){
    int pos = x % valoare;
    vector <int>::iterator it;
    for(it = M[pos].begin(); it != M[pos].end(); it++)
        if(*it == x)
            return it;
    return M[pos].end();
}

void insert(int x){
    int pos = x % valoare;
    if(findValue(x) == M[pos].end())
        M[pos].push_back(x);
}

void erase(int x){
    int pos = x % valoare;
    it = findValue(x);
    if (it != M[pos].end())
        M[pos].erase(it);
}

int main(){
    int tipOp,x;
    int pos = x % valoare;

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

    for(int i = 1; i <= n; i++){
        f>>tipOp>>x;
        if(tipOp == 1){
            insert(x);
            continue;
        }
        if(tipOp == 2){
            erase(x);
            continue;
        }
        g<<(findValue(x)!= M[pos].end());
    }

    f.close();
    g.close();
    return 0;
}