Cod sursa(job #731387)

Utilizator ColcerPColcer Paul ColcerP Data 7 aprilie 2012 22:57:56
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 kb
#include<fstream>
#include<vector>
#define valoare 700001

using namespace std;

vector<int>M[valoare];

vector<int>::iterator find(int x){

    vector<int>::iterator it;
    int position = x % valoare;

    for(it = M[position].begin(); it != M[position].end(); ++it)
        if(*it == x)
            return it;

    return M[position].end();
}

int main(){

    int n, i, tipOp ,x;

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

    for(i = 0; i < n; i++){

        f>>tipOp>>x;
        if(tipOp == 1){

            if(find(x) == M[x % valoare].end())
                M[x % prime].push_back(x);
        }
        else
            if(tipOp == 3){

                if(find(x) != M[x % valoare].end())
                    g<<"1\n";
                else
                    g<<"0\n";
            }
            else
                if(tipOp == 2){

                    vector<int>::iterator it;
                    it = find(x);
                    if(it != M[x % valoare].end())
                        M[x % valoare].erase(it);
                }
    }
    f.close();
    g.close();
    return 0;
}