Cod sursa(job #3001690)

Utilizator robertanechita1Roberta Nechita robertanechita1 Data 13 martie 2023 20:54:44
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
#include <bits/stdc++.h>

using namespace std;

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

const int P = 123457;
vector<int>h[123457];
int n;

int Find(int x){
    int p = x % P;
    for(int i = 0; i < h[p].size(); i++)
        if(h[p][i] == x)
            return 1;
    return 0;
}

void Add(int x){
    int p = x % P;
    if(!Find(x))
        h[p].push_back(x);
}

void Remove(int x){
    int p = x % P;
    if(Find(x)){
        int r = h[p].size();
        for(int i = 0; i < r; i++)
            if(h[p][i] == x){
                h[p][i] = h[p][r-1];
                break;
            }
        h[p].pop_back();
    }

}

int main()
{
    int x, y, task;
    fin >> n ;
    for(int i = 1; i <= n; i++){
        fin >> task >> x;
        if(task == 1)
            Add(x);
        else if(task == 2)
            Remove(x);
        else
            fout << Find(x) << "\n";

    }
    return 0;
}