Cod sursa(job #3162429)

Utilizator CipriEuCruceanu Ciprian Constantin CipriEu Data 29 octombrie 2023 11:16:00
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 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];

void addHash(int val){
    int e = val&mod;
    bool flag = true;
    for(int i=0; i<h[e].size(); i++)
        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++)
        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++)
        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;
        if(c==1) addHash(x);
        if(c==2) delHash(x);
        if(c==3) queHash(x);
    }
}