Cod sursa(job #3162430)

Utilizator CipriEuCruceanu Ciprian Constantin CipriEu Data 29 octombrie 2023 11:27:32
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.12 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n, c, x;
const int mod = 123457;
vector<int> h[mod+1];

void addHash(int val){
    int e = val&mod;
    bool flag = true;
    for(int i=0; i<h[e].size(); i++){
        //cout<<i<<"/"<<h[e].size()-1<<"\n";
        if(h[e][i] == val) flag = false;
    }
    if(flag) h[e].push_back(val);
}
void delHash(int val){
    int e = val&mod;
    for(int i=0; i<h[e].size(); i++){
        //cout<<i<<"/"<<h[e].size()-1<<"\n";
        if(h[e][i] == val){
            swap(h[e][i], h[e][h[e].size()-1]);
            h[e].pop_back();
        }
    }
}
void queHash(int val){
    int e = val&mod;
    for(int i=0; i<h[e].size(); i++){
        //cout<<i<<"/"<<h[e].size()-1<<"\n";
        if(h[e][i] == val){
            fout<<1<<"\n"; return;
        }
    }
    fout<<0<<"\n";
}

int main(){
    fin>>n;
    for(int i=1; i<=n; i++){
        fin>>c>>x;
        //cout<<c<<" "<<x<<"------------------------------\n";
        if(c==1) addHash(x);
        if(c==2) delHash(x);
        if(c==3) queHash(x);
    }
}