Cod sursa(job #2748021)

Utilizator Angel1IonitaAngel Ionita Angel1Ionita Data 29 aprilie 2021 20:40:24
Problema Hashuri Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

vector<int>::iterator findv(int x)
{
	int x_h = x % mod;
	vector<int>::iterator it;
    for (it = v[x_h].begin(); it != v[x_h].end(); ++it)
        if (*it == x)
            return it;
    return v[x_h].end();
}

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

void deletev(int x)
{
	int x_h = x % mod;
	vector<int>::iterator it=findv(x);
	if (v[x_h].end() != it)
		v[x_h].erase(it);
}

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
			if( findv(x) == v[x % mod].end())
				o<<'0'<<endl;
			else
				o<<'1'<<endl;
	}
}