Cod sursa(job #2885577)

Utilizator iioaaana777Ghergu Ioana iioaaana777 Data 6 aprilie 2022 11:39:18
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.4 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

int k = 666013;

int main()
{
    vector<vector<int> > hash1(k + 3);

    int N;
    int clasa, x, tipOp;

    fin>>N;

    for(int j = 0 ; j < N; ++j)
    {
        fin>>tipOp>>x;

        if(tipOp == 1)
        {
            clasa = x % k;
            hash1[clasa].push_back(x);
        }

        else
            if(tipOp == 2)
            {
                clasa = x % k;
                for(int i = 0; i < hash1[clasa].size(); ++i)
                    if(hash1[clasa][i] == x)
                    {
                        swap(hash1[clasa][i], hash1[clasa][hash1[clasa].size() - 1]);
                        hash1[clasa].pop_back();
                    }

            }

            else
                if(tipOp == 3)
                {
                    bool ok = 0;
                    clasa = x % k;
                    for(int i = 0; i < hash1[clasa].size(); ++i)
                        if(hash1[clasa][i] == x)
                            {
                                ok = 1;
                                fout<<'1'<<"\n";
                                break;
                            }
                    if(ok == 0)
                        fout<<'0'<<"\n";


                }
    }

    return 0;
}