Cod sursa(job #3213491)

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

#define ll long long

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

using namespace std;

const int MOD=999983;

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

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

int main()
{
    fin.tie(0); fin.sync_with_stdio(false);
    /*
    int biggest_prim=0;
    for (int i=2; i*i<=1000000; i++) {
        if (ciur[i]==0) {
            for (int j=i*i; j<=1000000; j+=i) {
                ciur[j]=1;
            }
        }
    }
    for (int j=1000000; 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;
}