Cod sursa(job #2766652)

Utilizator toma_ariciuAriciu Toma toma_ariciu Data 2 august 2021 17:41:36
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

ifstream f("hashuri.in");
ofstream o("hashuri.out");
#define mod 666013
int N, op,x,i;
vector<int> v[mod];

int findv(int x)
{
	int x_h = x % mod;
	int l = v[x_h].size();
	for (int i = 0; i < l; i++)
		if (v[x_h][i] == x)
			return 1;
	return 0;
}

void insertv(int x)
{
	int x_h = x % mod;
	if (!findv(x))
		v[x_h].push_back(x);
}

void deletev(int x)
{
	int x_h = x % mod;
	int l = v[x_h].size();
	for (int i = 0; i < l; i++)
		if (v[x_h][i] == x)
		{
			v[x_h][i] = v[x_h][l - 1];
			v[x_h].pop_back();
			break;
		}
}

int main()
{
	f >> N;
	for (i = 0; i < N; i++)
	{
		f >> op >> x;
		if (op == 1)
			insertv(x);
		else if (op == 2)
			deletev(x);
		else
			o << findv(x) << endl;
	}
}