Cod sursa(job #2886664)

Utilizator Iordache_AnaIordache Ana-Georgiana Iordache_Ana Data 8 aprilie 2022 00:25:24
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.92 kb
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
#define k 666013
vector <int> my_hash[k+5];
int main()
{
    int N, i, operatie,clasa,x,j,found;
    f>>N;
    for (i=1; i<=N; i++)
    {
        f>>operatie>>x;
        clasa=x%k;
        found=0;
        for(j=0; j<my_hash[clasa].size(); j++)
            if(my_hash[clasa][j]==x)
            {
                found=1;
                break;
            }
        if(operatie==1)
        {
            if (found==0)
                my_hash[clasa].push_back(x);
        }
        else if(operatie==2)
        {
            if(found==1)
            {
                swap(my_hash[clasa][j],my_hash[clasa].back());
                my_hash[clasa].pop_back();
            }
        }
        else if(operatie==3)
            g<<found<<'\n';
    }
    return 0;
}