Cod sursa(job #3130945)

Utilizator TediCutuTudor Chitu TediCutu Data 18 mai 2023 21:07:57
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.25 kb
#include<bits/stdc++.h>
using namespace std;
ifstream in("sea.in");
ofstream out("sea.out");

vector <vector <int>> hashh;
int p = 116351, k, c, val, x;

void ins(int x, int val)
{
    for(int j = 0; j < hashh[x].size(); j++)
        if(hashh[x][j] == val)
            return;
    hashh[x].push_back(x);
}

void del(int x)
{
    for(int j = 0; j < hashh[x].size(); j++)
        if(hashh[x][j] == val)
        {
            hashh[x].erase(hashh[x].begin() + j);
            break;
        }
}
int main()
{
    in >> k;
    for(int i = 1; i <= k; i++)
    {
        in >> c >> val;
        x = val % p;
        while(hashh.size() <= x)
            hashh.push_back({});
        switch(c)
        {
        case 1:
        {
            ins(x, val);
            break;
        }
        case 2:
        {
            del(x);
            break;
        }
        case 3:
        {
            int j;
            for(j = 0; j < hashh[x].size(); j++)
                if(hashh[x][j] == val)
                {
                    out << 1 << endl;
                    break;
                }
            if(j == hashh[x].size())
                out << 0 << endl;
            break;
        }
        }
    }
    return 0;
}