Cod sursa(job #3130947)

Utilizator RadushCordunianu Radu Radush Data 18 mai 2023 21:09:53
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.4 kb
#include <iostream>

#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
class Hash{
private:
    vector<int> k;
    vector<int>v;
public:
    Hash(){
        k.resize(0);
        v.resize(0);
    }
    void insert(int val){
        auto x=find(k.begin(),k.end(),val);
        if(x==k.end()){
            k.resize(k.size()+1);
            v.resize(v.size()+1);
            k[k.size()-1]=val;
            v[v.size()-1]=1;
        }
        else{
            v[x-k.begin()]+=1;
        }
    }
    void remove(int val){
        auto x=find(k.begin(),k.end(),val);
        if(x!=k.end()){
            v[x-k.begin()]-=1;
            if(v[x-k.begin()]==0){
                k.erase(std::remove(k.begin(),k.end(),val),k.end());
                v.erase(std::remove(v.begin(),v.end(),0),v.end());
            }
        }
    }
    bool getval(int val){
        auto x=find(k.begin(),k.end(),val);
        return x!=k.end();
    }
};
int main() {
    Hash h;
    int n,op,x;
    fin>>n;
    for(int i=0;i<n;i++){
        fin>>op>>x;
        switch(op){
            case 1:
                h.insert(x);
                break;
            case 2:
                h.remove(x);
                break;
            case 3:
                fout<<h.getval(x)<<"\n";
                break;
            default:
                break;
        }
    }
    return 0;
}