Cod sursa(job #3277784)

Utilizator TeogaloiuMatei Ionescu Teogaloiu Data 17 februarie 2025 13:29:56
Problema Hashuri Scor 30
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.42 kb
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout ("hashuri.out");
const int mod=666013;
const int base=11;
long long powers[15];
void powermaker()
{
    int check=1;
    for(int i=1;i<=14;i++)
    {
        powers[i]=check;
        check*=base;
        check%=mod;
    }
}
vector <vector<int>> v;
int hasher(int x)
{
    long long newx=0;
    int p=1;
    while(x)
    {
        newx+=powers[p]*(x%10);
        newx%=mod;
        p++;
        x/=10;
    }
    return newx;
}
int main()
{
    int n;
    cin>>n;
    v.resize(mod + 1);
    for(int k=1;k<=n;k++)
    {
        int c;
        cin>>c;
        int val,hashed;
        cin>>val;
        hashed=hasher(val);
        if(c==1)
            v[hashed].push_back(val);
        if(c==2)
        {
            for(int i=0;i<v[hashed].size();i++)
                if(v[hashed][i]==val){
                {
                    int last_idx = v[hashed].size() - 1;
                    swap(v[hashed][i],v[hashed][last_idx]);
                    v[hashed].pop_back();
                    break;
                }
            }
        }
        if(c==3)
        {
            bool flag=true;
            for(int i=0;i<v[hashed].size();i++)
                if(v[hashed][i]==val){
                    cout<<"1\n";
                    flag=false;
                }
            if(flag)
                cout<<"0\n";
        }
           
    }
    return 0;
}