Cod sursa(job #2950604)

Utilizator AndreiBOTOBotocan Andrei AndreiBOTO Data 4 decembrie 2022 11:59:31
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.98 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

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

const int MOD=666013;

vector<vector<int>>hashv;

void ins(int x)
{
    for(auto i:hashv[x%MOD])
        if(x==i)
            return ;
    hashv[x%MOD].push_back(x);
}

void del(int x)
{
    for(auto i=hashv[x%MOD].begin();i!=hashv[x%MOD].end();i++)
    {
        if(*i==x)
        {
            hashv[x%MOD].erase(i);
            return ;
        }
    }
}

void verif(int x)
{
    for(auto i:hashv[x%MOD])
    {
        if(i==x)
        {
            fout<<1<<"\n";
            return ;
        }
    }
    fout<<0<<"\n";
}

int main()
{
    int n,i,t,q;
    fin>>q;
    hashv.resize(MOD+1);
    while(q--)
    {
        fin>>t>>n;
        if(t==1)
            ins(n);
         if(t==2)
            del(n);
        else
       if(t==3)
            verif(n);
    }
    return 0;
}