Cod sursa(job #3159493)

Utilizator dobreraduDobre Radu Fabian dobreradu Data 21 octombrie 2023 13:47:40
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.87 kb
#include <bits/stdc++.h>

using namespace std;
const int BAZA = 37;
const int MOD = 666013;

ifstream in("hashuri.in");
ofstream out("hashuri.out");
vector <int> v[MOD];
int hashuri( int a ){
    int hsh = 0;
    while( a > 0 ){
        hsh = (hsh * BAZA + a%10) % MOD;
        a /= 10;
    }
    return hsh;
}
int main()
{
    int n;
    in >> n;
    for( int i = 0; i < n; i++ ){
        int cer, a;
        in >> cer >> a;
        int hsh = hashuri(a);
        auto it = find( v[hsh].begin(), v[hsh].end(), a);
        if( cer == 1 && it == v[hsh].end()){
            v[hsh].push_back(a);
        }
        else if( cer == 2 && it != v[hsh].end()){
            v[hsh].erase(it);
        }
        else if( cer == 3 && it != v[hsh].end() )
            out << 1 << "\n";
        else if ( cer == 3 )
            out << 0 << "\n";
    }
    return 0;
}