Cod sursa(job #2483077)

Utilizator savigunFeleaga Dragos-George savigun Data 29 octombrie 2019 11:40:09
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <iostream>
#include <fstream>
#include <list>
#include <algorithm>
using namespace std;

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

#define mod 666013
list<int> H[mod];

void add(int x)
{
	int address = x % mod;
	if (find(H[address].begin(), H[address].end(), x) == H[address].end())
		H[address].push_back(x);
}

void remove(int x)
{
	int address = x % mod;
	H[address].remove(x);
}

int has(int x)
{
	int address = x % mod;
	list<int>::iterator it = find(H[address].begin(), H[address].end(), x);
	if (it != H[address].end()) return 1;
	return 0;
}

int main()
{
	int n, o, x;
	fin >> n;

	for (int i = 1; i <= n; ++i)
	{
		fin >> o >> x;
		if (o == 1) add(x);
		else if (o == 2) remove(x);
		else fout << has(x) << "\n";
	}

	return 0;
}