Cod sursa(job #2558103)

Utilizator richardbaczur1Baczur Richard richardbaczur1 Data 26 februarie 2020 12:04:23
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.09 kb
#include <bits/stdc++.h>
#define MOD 666013
#define infile "hashuri.in"
#define outfile "hashuri.out"

using namespace std;

int n, op, x;
vector<int> v[MOD];

inline vector<int>::iterator find_value(int x)
{
	int line = x % MOD;
	vector<int>::iterator it;
	for (it = v[line].begin(); it != v[line].end(); ++it)
	{
		if (*it == x)
		{
			return it;
		}
	}
	return v[line].end();
}

inline void insert_value(int x)
{
	int line = x % MOD;
	if (find_value(x) == v[line].end())
	{
        v[line].push_back(x);
	}
}

inline void delete_value(int x)
{
	int line = x % MOD;
	vector<int>::iterator it = find_value(x);

    if (it != v[line].end())
    {
        v[line].erase(it);
    }
}

int main() {
	freopen(infile, "r", stdin);
	freopen(outfile, "w", stdout);

	scanf("%d", &n);
	while (n--)
	{
		scanf("%d %d", &op, &x);
		switch (op)
		{
			case 1:
				insert_value(x);
				break;
			case 2:
				delete_value(x);
				break;
			case 3:
				vector<int>::iterator it = find_value(x);
				if (it == v[x % MOD].end()) printf("0\n");
				else printf("1\n");
				break;
		}
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}