Cod sursa(job #3277713)

Utilizator PsyDuck1914Feraru Rares-Serban PsyDuck1914 Data 17 februarie 2025 12:16:56
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.74 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f ("hashuri.in");
ofstream g ("hashuri.out");

const int NMAX = 1e6;
const int MOD = 666013;
const int BAZA = 29;

vector<int> buck[MOD + 1];

int hashh(int x){
    
    int cnt = 0;
    long long sum = 0;
    
    while(x){
        
        sum = (sum + (long long)pow(BAZA, cnt) * (x % 10) % MOD) % MOD;
        
        cnt ++;
        x /= 10;
        
    }
    
    return sum;
    
}

int main()
{
    
    int q;
    f >> q;
    
    for(int i=1; i<=q; i++){
        
        int tip, val;
        f >> tip >> val;
        
        if(tip == 1){
            
            bool ok = false;
            
            int idx = hashh(val);
            
            for(int i=0; i<buck[idx].size(); i++)
                if(buck[idx][i] == val)
                    ok = true;
            
            if(ok == false)
                buck[idx].push_back(val);
            
        }else if(tip == 2){
            
            int ok = -1;
            
            int idx = hashh(val);
            
            for(int i=0; i<buck[idx].size(); i++)
                if(buck[idx][i] == val)
                    ok = i;
                    
            if(ok > -1){
                
                buck[idx].erase(buck[idx].begin() + ok);
                
            }
            
        }else{
            
            bool ok = false;
            
            int idx = hashh(val);
            
            for(int i=0; i<buck[idx].size(); i++)
                if(buck[idx][i] == val)
                    ok = true;
                    
            if(ok == true){
                
                g << 1 << "\n";
                
            }else g << 0 << "\n";
            
        }
        
    }
    

    return 0;
}