Pagini recente » Cod sursa (job #3166972) | Cod sursa (job #2487729) | Cod sursa (job #2904814) | Cod sursa (job #473804) | Cod sursa (job #2276769)
#include <stdio.h>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;
int N;
#define PRIME 666013
vector<int> hashtab[PRIME];
int main()
{
ifstream input("hashuri.in");
ofstream output("hashuri.out");
int i, tip, x;
input >> N;
unsigned int slot;
vector<int>::iterator it;
for (i = 1; i <= N; i++)
{
input >> tip >> x;
slot=x%PRIME;
switch(tip){
case 1:
it = find(hashtab[slot].begin(), hashtab[slot].end(), x);
if(it==hashtab[slot].end())
hashtab[slot].push_back(x);
break;
case 2:
it = find(hashtab[slot].begin(), hashtab[slot].end(), x);
if(it!=hashtab[slot].end())
hashtab[slot].erase(it);
break;
case 3:
it = find(hashtab[slot].begin(), hashtab[slot].end(), x);
if(it!=hashtab[slot].end())
output << "1" << endl;
else
output << "0" << endl;
break;
}
}
input.close();
output.close();
return 0;
}