Cod sursa(job #2891139)

Utilizator andlftLefter Andrei andlft Data 17 aprilie 2022 17:33:17
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.66 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

vector <int> buckets[524288];
int main()
{
    int n;
    fin>>n;
    int op_code;
    int value;
    int poz;
    int f;

    for(int i = 0; i < n; i++)
    {
        fin>>op_code;
        fin>>value;
        poz = value % 523227;

        if(op_code == 1)
        {
            f = 0;
            //inserare
            for(int j = 0; j < buckets[poz].size(); j++)
            {
                if(value == buckets[poz][j])
                {
                    f = 1;
                    break;
                }
            }
            if (f == 0)
            {
                buckets[poz].push_back(value);
            }
        }

        if(op_code == 2)
        {
            //stergere
            for(int j = 0; j< buckets[poz].size(); j++)
            {
                if(value == buckets[poz][j])
                {
                    buckets[poz].erase(buckets[poz].begin()+j);
                    break;
                }
            }
        }
        if(op_code == 3)
        {
            f = 0;
            //interogare
            for(int j = 0; j < buckets[poz].size(); j++)
            {
                if(value == buckets[poz][j])
                   {
                       f = 1;
                       break;
                   }
            }

            if(f == 1)
            {
                fout<< 1 << "\n";
            }
            else
            {
                fout<< 0 << "\n";
            }

        }
    }


    return 0;
}