Cod sursa(job #2195410)

Utilizator ancabdBadiu Anca ancabd Data 16 aprilie 2018 12:25:40
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream cin ("hashuri.in");
ofstream cout ("hashuri.out");

#define MOD 999983

int n;
vector< vector<int> > a;

void Add(int x)
{
    int h = x % MOD;
    a[h].push_back(x);
}
void Delete(int x)
{
    int h = x % MOD;
    for (unsigned int i = 0; i < a[h].size(); i ++)
        if (a[h][i] == x)
        {
            a[h].erase(a[h].begin() + i);
            return;
        }
}
bool Query(int x)
{
    int h = x % MOD;
    for (unsigned int i = 0; i < a[h].size(); i ++)
        if (a[h][i] == x)
            return 1;
    return 0;
}
int main()
{
    cin >> n;
    a = vector< vector<int> >(MOD);

    for (int i = 1, x, cer; i <= n; i ++)
    {
        cin >> cer >> x;
        if (cer == 1)Add(x);
        else if (cer == 2)Delete(x);
        else cout << Query(x) << '\n';
    }
    return 0;
}