Cod sursa(job #2647070)

Utilizator akumariaPatrascanu Andra-Maria akumaria Data 2 septembrie 2020 21:11:17
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.79 kb
#include <cstdio>
#include <vector>

using namespace std;

int main() {
	freopen("hashuri.in", "r", stdin);
	freopen("hashuri.out", "w", stdout);

	int h = 666013;
	vector<vector<int>> numbers(h);

	int n, t, x, hash_res, pos;
	scanf("%d", &n);
	for(int i=0; i<n; ++i)
	{
		scanf("%d%d", &t, &x);
		hash_res = x%h;
		pos = -1;
		for(int j = 0; j< numbers[hash_res].size(); ++j)
			if (numbers[hash_res][j] == x) {
				pos = j;
				break;
			}

		switch(t) {
			case 1:
				if (pos == -1)
					numbers[hash_res].push_back(x);
				break;
			case 2:
				if (pos != -1) {
					numbers[hash_res][pos] = numbers[hash_res][numbers[hash_res].size() - 1];
					numbers[hash_res].pop_back();
				}
				break;
			case 3:
				printf("%d\n", pos != -1);
		}
	}

	return 0;
}