Pagini recente » Cod sursa (job #1298346) | Cod sursa (job #1341396) | Cod sursa (job #1101175) | Cod sursa (job #1894348) | Cod sursa (job #1775384)
//
// main.cpp
// Hashuri
//
// Created by Nasca Sergiu Alin on 10/10/16.
// Copyright © 2016 Nasca Sergiu Alin. All rights reserved.
//
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
vector<int> a[666014];
int find_hash(int x)
{
int hash = x % 666013;
for(int i = 0; i < a[hash].size(); ++i)
{
if(a[hash][i] == x)
{
return i;
}
}
return -1;
}
void add_hash(int x)
{
int hash = x % 666013;
int pos = find_hash(x);
if(pos == -1)
{
a[hash].push_back(x);
}
}
void erase_hash(int x)
{
int hash = x % 666013;
int pos = find_hash(x);
if(pos >= 0)
{
a[hash].erase(a[hash].begin() + pos);
}
}
int main(int argc, const char * argv[])
{
// 666013
freopen("hashuri.in", "r", stdin);
freopen("hashuri.out", "w", stdout);
int n, op, x;
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
{
scanf("%d %d", &op, &x);
if(op == 1)
{
add_hash(x);
}
else if(op == 2)
{
erase_hash(x);
}
else if(op == 3)
{
int pos = find_hash(x);
if(pos == -1)
{
printf("0\n");
}
else printf("1\n");
}
}
return 0;
}