Mai intai trebuie sa te autentifici.
Cod sursa(job #2742798)
Utilizator | Data | 21 aprilie 2021 20:17:40 | |
---|---|---|---|
Problema | Hashuri | Scor | 70 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.93 kb |
#include <iostream>
#include <fstream>
#include <vector>
#define prime 666013
using namespace std;
vector<int> hashh[prime];
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
void add(int x)
{
hashh[x % prime].push_back(x);
}
void del(int x)
{
for (int i = 0; i < hashh[x % prime].size(); i++)
{
if (hashh[x % prime][i] == x)
{
hashh[x % prime][i] = hashh[x % prime][hashh[x % prime].size() - 1];
hashh[x % prime].pop_back();
break;
}
}
}
bool get(int x)
{
for (int i = 0; i < hashh[x % prime].size(); i++)
{
if (hashh[x % prime][i] == x)
return true;
}
return false;
}
int main()
{
int n, op, x;
fin >> n;
for (int i = 0; i < n; i++)
{
fin >> op >> x;
if (op == 1)
{
add(x);
}
else if (op == 2)
{
del(x);
}
else
{
if (get(x))
{
fout << 1 << endl;
}
else
{
fout << 0 << endl;
}
}
}
return 0;
}