Cod sursa(job #3163402)

Utilizator AlexandruDrg23Draghici Alexandru AlexandruDrg23 Data 31 octombrie 2023 13:13:23
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.2 kb
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <vector>
using namespace std;

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

unordered_map<int, vector<int> > hsh;
int n,op,arg;

int main()
{
    fin>>n;
    for(int k=1;k<=n;k++)
    {
        fin>>op>>arg;
        if(op==1)
        {
            (hsh[arg%500009]).push_back(arg);
        }
        else if(op==2)
        {
            int carg=arg%500009;
            if(hsh[carg].empty())
                continue;
            for(vector<int>::iterator  ele=hsh[carg].begin();ele!=hsh[carg].end();ele++)
            {
                if(*ele==arg)
                {
                    hsh[carg].erase(ele);
                    break;
                }
            }
        }
        else
        {
            bool test=false;
            int carg=arg%500009;
            if(hsh[carg].empty())
                test=false;
            for(vector<int>::iterator  ele=hsh[carg].begin();ele!=hsh[carg].end() && test==false;ele++)
            {
                if(*ele==arg)
                    test=true;
            }
            fout<<test<<'\n';
        }
    }

    return 0;
}