Cod sursa(job #3202303)

Utilizator vlad_miscociMiscoci Vlad Andrei vlad_miscoci Data 11 februarie 2024 13:05:47
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>
#include <vector>

using namespace std;
const int MOD = 666013;
vector<int> h[MOD];
int v[1000001];
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
bool caut(int x)
{
    int cod = x % MOD, i=0;
    while(i < h[cod].size() && h[cod][i] != x)
        i++;
    return i < h[cod].size();
}

void adaug(int x)
{
    int cod = x % MOD, i=0;
    while(i < h[cod].size() && h[cod][i] != x)
        i++;
    if(i == h[cod].size())
        h[cod].push_back(x);
}

void sterg(int x)
{
    int cod = x % MOD, i=0;
    while(i < h[cod].size() && h[cod][i] != x)
        i++;
    if(i < h[cod].size())
        h[cod].erase(h[cod].begin() + i);
}
int main()
{
    int n, op, x, ras;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> op >> x;
        if(op == 1)
            adaug(x);
        else if(op == 2)
            sterg(x);
        else if(op == 3)
            cout <<caut(x) << '\n';
    }
    return 0;
}