Cod sursa(job #2272055)

Utilizator vladcoroian2001Vlad Coroian vladcoroian2001 Data 29 octombrie 2018 17:39:24
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.03 kb
#include <fstream>
#include <vector>

using namespace std;
ifstream fi("hashuri.in");
ofstream fo("hashuri.out");
const int MOD=100013;
int n,op,x;
vector <int> HASH[MOD];
void inserare(int x)
{
    int rest=x%MOD;
    int ok=0;
    for(auto y: HASH[rest])
        if(y==x)
            ok=1;
    if(ok==0)
        HASH[rest].push_back(x);
}
void stergere(int x)
{
    int rest=x%MOD;
    for(auto (&it): HASH[rest])
        if(it==x)
        {
            swap(it,HASH[rest][HASH[rest].size()-1]);
            HASH[rest].pop_back();
            break;
        }
}
void afisare(int x)
{
    int rest=x%MOD;
    for(auto y:HASH[rest])
        if(y==x)
        {
            fo<<1<<"\n";
            return ;
        }
    fo<<0<<"\n";
}
int main()
{
    fi>>n;
    for(int i=1;i<=n;i++)
    {
        fi>>op>>x;
        if(op==1)
            inserare(x);
        if(op==2)
            stergere(x);
        if(op==3)
            afisare(x);
    }
    fi.close();
    fo.close();
    return 0;
}