Cod sursa(job #1997739)

Utilizator MateiAruxandeiMateiStefan MateiAruxandei Data 5 iulie 2017 11:38:18
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <fstream>
#include <algorithm>

#define M 666013
using namespace std;

vector<int> v[M];

int h(int x){
	return x % M;
}

bool src(int x){
	return v[h(x)].end() != find(v[h(x)].begin(), v[h(x)].end(), x);
}

void del(int x){
	if (src(x)){
		auto pos = find(v[h(x)].begin(), v[h(x)].end(), x);
		v[h(x)].erase(pos);
	}
}

void ins(int x){
	if (!src(x)){
		v[h(x)].push_back(x);
	}
}

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

    int op, x;

	int N;
    for (fin >> N; N; --N)
    {
        fin >> op >> x;
        if (op == 1)
        {
        	ins(x);
        	continue;
        }
        if (op == 2)
        {
        	del(x);
            continue;
        }
        fout << src(x) << '\n';
    }
    return 0;
}