Cod sursa(job #2894693)

Utilizator elenaa_g23Elena Georgescu elenaa_g23 Data 28 aprilie 2022 01:52:08
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb

#include <fstream>
#include<vector>

using namespace std;

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

vector<int> myhash[666015];

int main()
{
    int k=666013;
    int n, operatie, element;
    f>>n;
    int clasa;
    for(int i=1;i<=n;i++)
        {f>>operatie>>element;
        clasa=element%k;
        int found=0;
        for(unsigned int j=0;j<myhash[clasa].size();j++)
            if (myhash[clasa][j]==element)
            {
                found = 1;
                break;
            }
        if(operatie==1)

        {  if (found==0)
                myhash[clasa].push_back(element);
        }

        if(operatie==2)
        {  if (found==1)
            {
                swap(element, myhash[clasa].back());
                myhash[clasa].pop_back();
            }

        }

        if(operatie==3)
        {
            g<<found<<'\n';

        }


        }

}