Cod sursa(job #3129038)

Utilizator arobyRobert Acsente aroby Data 12 mai 2023 12:23:35
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.34 kb
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int p = 666103;
int n, x, y;
int main()
{
    vector<vector<int>> hash(666103);

    in >> n;
    for (int j = 0; j < n; j++)
    {
        in >> x >> y;
        if (x == 1)
        { /// inserare
            int k = y % p;
            hash[k].push_back(y);
        }
        else if (x == 2)
        { /// delete
            int k = y % p;
            int aux = hash[k].size();
            int ok = 0;
            for (int i = 0; i < aux; i++)
            {
                if (hash[k][i] == y)
                {
                    ok = 1;
                }
                if (ok == 1)
                {
                    if(i==aux-1)
                        hash[k].resize(i);
                    else
                    hash[k][i] = hash[k][i + 1];
                }
                    
            }
        }

        else
        {
            int k = y % p;
            int ok=0;
            int aux = hash[k].size();
            for (int i = 0; i < aux; i++)
                if (hash[k][i] == y)
                   { ok=1;break;}
            if(ok)
            out<<1<<endl;
            else
            out<<0<<endl;        }
    }
    return 0;
}