Cod sursa(job #2780899)

Utilizator filiptudose2007Tudose Filip filiptudose2007 Data 8 octombrie 2021 09:37:10
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1 kb
#include <bits/stdc++.h>

using namespace std;
int ind;
const int Mod=666013;
vector <int> h[Mod];
vector <int> :: iterator it;
vector <int> :: iterator Find(int x)
{
    for(it=h[ind].begin(); it!=h[ind].end(); ++it)
        if(*it==x)return it;
    return it;
}
void adauga(int x)
{
    if(it==h[ind].end())h[ind].push_back(x);
}
void sterge(int x)
{
    if(it!=h[ind].end())h[ind].erase(it);
}
void scrie(int x)
{
    if(it==h[ind].end())cout<<0;
    else cout<<1;
    cout<<'\n';
}
int main()
{

    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    cin.sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin>>q;
    for(int i=1; i<=q; ++i)
    {
        int t,x;
        cin>>t>>x;
        ind=x%Mod;
        Find(x);
        if(t==1)
        {
            adauga(x);
        }
        else if(t==2)
        {
            sterge(x);
        }
        else if(t==3)
        {
            scrie(x);
        }
    }
    return 0;
}