Cod sursa(job #2830013)

Utilizator NutaAlexandruASN49K NutaAlexandru Data 9 ianuarie 2022 13:04:58
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.22 kb
#include <bits/stdc++.h>
using namespace std;
class map_de_buget
{
private:
    const int mod=100000;
    vector<int>a[100000];
public:
    vector<int>::iterator caut(int x)
    {
        int d=x%mod;
        return find(a[d].begin(),a[d].end(),x);
    }
    void adaugare(int x)
    {
        int d=x%mod;
        if(find(a[d].begin(),a[d].end(),x)==a[d].end())
        {
            a[d].push_back(x);
        }
    }
    void scadere(int x)
    {
        int d=x%mod;
        auto c=caut(x);
        if(c!=a[d].end())
        {
            a[d].erase(c);
        }
    }
    bool apare(int x)
    {
        int d=x%mod;
        if(find(a[d].begin(),a[d].end(),x)==a[d].end())
        {
            return 0;
        }
        else
        {
            return 1;
        }
    }
};
map_de_buget mp;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int main()
{
    int n;
    fin>>n;
    while(n--)
    {
        int a,b;
        fin>>a>>b;
        if(a==1)
        {
            mp.adaugare(b);
        }
        else if(a==2)
        {
            mp.scadere(b);
        }
        else
        {
            fout<<mp.apare(b)<<"\n";
        }
    }
    return 0;
}