Cod sursa(job #2065360)

Utilizator shantih1Alex S Hill shantih1 Data 13 noiembrie 2017 18:47:36
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <vector>
#define max 666013

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

int n, o, x;
vector <int> H[max];

void adaug (int x)
{
	int ind = x%max;
	for (int i = 0; i < H[ind].size(); i++)
		if (H[ind][i] == x)	
			return;
	H[ind].push_back(x);
}

void scot (int x)
{
	int ind = x%max;
	bool ok = 0;
	for (int i = 0; i < H[ind].size(); i++)
	{
		if (H[ind][i] == x)	ok = 1;
		if (ok && i <= H[ind].size()-2)	H[ind][i] = H[ind][i+1];
	}
	if (H[ind].size())	H[ind].pop_back();
}

bool este (int x)
{
	int ind = x%max;
	for (int i = 0; i < H[ind].size(); i++)
		if (H[ind][i] == x)
			return 1;
	return 0;
}

int main () {
	
	fin >> n;
	for (int i = 1; i <= n; i++)
	{
		fin >> o >> x;
		if (o == 1)	adaug(x);
		if (o == 2)	scot(x);
		if (o == 3)	fout << este(x) << "\n";
	}
}