Cod sursa(job #3300387)

Utilizator deliaandreeaddelia andreea deliaandreead Data 15 iunie 2025 11:59:38
Problema Hashuri Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.19 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

vector<vector<int>>v;

int hashul(int x){
    int b=1;
    int mod=999983;
    int nr=0;
    while(x>0){
        nr=(nr+b*(x%10))%mod;
        b*=13;
        x/=10;
    }
    return nr;
}
int check(int h, int x){
    for(int i=0;i<v[h].size();i++){
        if(v[h][i]==x)
            return i;
    }
    return -1;
}
int main()
{   
    int n;
    fin>>n;
    v.resize(999983);
    for(int i=1;i<=n;i++){
        int c, x;
        fin>>c>>x;
        if(c==1){///adaug x (daca nu e)
            int h=hashul(x);
            if( check(h,x)==-1)
                v[h].push_back(x);
        }
        else if (c==2){///sterg x (daca e)
            int h=hashul(x);
            int i=check(h,x);
            if( i!=-1){
                swap(v[h][i],v[h][v[h].back()]);
                v[h].pop_back();
            }
        }
        else{///1 daca e, 0 daca nu e
            if(check(hashul(x),x)!=-1)
                fout<<1<<'\n';
            else
                fout<<0<<'\n';
        }
    }
   
    
    return 0;
}