Cod sursa(job #3146507)

Utilizator PetraPetra Hedesiu Petra Data 21 august 2023 12:48:32
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <vector>

#define MOD 666013

using namespace std;

ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");

vector<int> hashh[MOD];
int n;

void add(int x)
{
    hashh[x%MOD].push_back(x);
}
void remove(int x)
{
    for (int i = 0; i < hashh[x%MOD].size(); i++)
    {
        if (hashh[x%MOD][i] == x)
        {
            hashh[x%MOD][i] = hashh[x%MOD][hashh[x%MOD].size()-1];
            hashh[x%MOD].pop_back();
            return;
        }
    }
}
int exists(int x)
{
    for (int i = 0; i < hashh[x%MOD].size(); i++)
        if (hashh[x%MOD][i] == x)
            return 1;
    return 0;
}

int main()
{
    fin >> n;
    for (int i = 0; i < n; i++)
    {
        int op, x;
        fin >> op >> x;
        if (op == 1) add(x);
        else if (op == 2) remove(x);
        else if (op == 3) fout << exists(x) << "\n";
    }
    return 0;
}