Cod sursa(job #2885804)

Utilizator VladTalpigaVlad Talpiga VladTalpiga Data 6 aprilie 2022 16:49:49
Problema Hashuri Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.94 kb
#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

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

#define k 666013

vector <int> myhash[k+5];

int n, i, j, x, caz, clasa, gasit, poz;

int main()
{

f>>n;

for(i = 1; i <= n; i++){

    f>>caz>>x;

    gasit = 0;

    clasa = x % k;

    for(j = 0; j < myhash[clasa].size(); j++){

            if(myhash[clasa][j] == x){

                gasit = 1;

                poz = j;

                break;
            }
    }

    if(caz == 1){

        if(gasit == 0)

            myhash[clasa].push_back(x);

    }else{

    if(caz == 2){

        if(gasit == 1){

            swap(myhash[clasa][j], myhash[clasa][myhash[clasa].size()]);
            myhash[clasa].pop_back();
        }


    }else{

        if(gasit == 1)

            g<<"1\n";
        else
            g<<"0\n";

}}

}


    return 0;
}