Mai intai trebuie sa te autentifici.
Cod sursa(job #2065316)
Utilizator | Data | 13 noiembrie 2017 18:21:07 | |
---|---|---|---|
Problema | Hashuri | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.93 kb |
#include <iostream>
#include <fstream>
#include <vector>
#define max 666013
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n, o, x;
vector <int> H[max];
void adaug (int x)
{
int ind = x%max;
bool ok = 0;
for (int i = 0; i < H[ind].size(); i++)
if (H[ind][i] == x)
{
ok = 1;
i = int(H[ind].size());
}
if (ok == 0) H[ind].push_back(x);
}
void scot (int x)
{
int ind = x%max;
bool ok = 0;
for (int i = 0; i < H[ind].size(); i++)
{
if (H[ind][i] == x) ok = 1;
if (ok == 1) H[ind][i] = H[ind][i+1];
}
if (H[ind].size() > 0) H[ind].pop_back();
}
bool este (int x)
{
int ind = x%max;
bool r = 0;
for (int i = 0; i < H[ind].size(); i++)
if (H[ind][i] == x)
{
r = 1;
i = int(H[ind].size());
}
return r;
}
int main () {
fin >> n;
for (int i = 1; i <= n; i++)
{
fin >> o >> x;
if (o == 1) adaug(x);
if (o == 2) scot(x);
if (o == 3) fout << este(x) << "\n";
}
}