Cod sursa(job #3213488)

Utilizator Alex_DumitrascuAlex Dumitrascu Alex_Dumitrascu Data 13 martie 2024 10:33:17
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.28 kb
#include <bits/stdc++.h>

#define ll long long

//#define fin cin
//#define fout cout

using namespace std;

const int MOD=99991;

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

vector< list<int> > hash_list (100005);
//bool ciur[100005];

int main()
{
    fin.tie(0); fin.sync_with_stdio(false);
    /*
    int biggest_prim=0;
    for (int i=2; i*i<=100000; i++) {
        if (ciur[i]==0) {
            for (int j=i*i; j<=100000; j+=i) {
                ciur[j]=1;
            }
        }
    }
    for (int j=100000; j>=0; j--) {
        if (ciur[j]==0) {
            biggest_prim=j;
            break;
        }
    }
    cout<<biggest_prim<<endl;
    */ //Pentru a gasi valoarea lui MOD;
    int n, a, b; fin>>n;
    for (int i=1; i<=n; i++) {
        fin>>a>>b;
        int index=b%MOD;
        bool in_list=false;
        auto it=find(hash_list[index].begin(), hash_list[index].end(), b);
        if (a==1) {
            if (it==hash_list[index].end()) {
                hash_list[index].insert(it, b);
            }
        }
        if (a==2) {
            if (it!=hash_list[index].end()) {
                hash_list[index].erase(it);
            }
        }
        if (a==3) {
            bool ans=it!=hash_list[index].end();
            fout<<ans<<'\n';
        }
    }
    return 0;
}