Cod sursa(job #2947636)

Utilizator cezarTriscaVicolCezar Trisca Vicol 2 cezarTriscaVicol Data 26 noiembrie 2022 15:12:20
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

int N, op, val;
const int prime = 100003;
vector<int> hashMap[prime];

void add(int val){
    int key = val % prime;
    for(auto it:hashMap[key])
        if(it == val)
            return ;
    hashMap[key].push_back(val);
}

void delet(int val){
    int key = val % prime;
    int n = hashMap[key].size();
    for(int i=0;i<n;i++)
        if(hashMap[key][i] == val){
            hashMap[key].erase(hashMap[key].begin()+i);
            return ;
        }
    return ;
}

int found(int val){
    int key = val % prime;
    for(auto it:hashMap[key])
        if(it == val)
            return 1;
    return 0;
}

int main()
{
    f>>N;
    for(;N;N--){
        f>>op>>val;
        if(op == 1)
            add(val);
        else if(op == 2)
            delet(val);
        else
            g<<found(val)<<'\n';
    }
    return 0;
}