Cod sursa(job #2541027)

Utilizator AndreeaGherghescuAndreea Gherghescu AndreeaGherghescu Data 7 februarie 2020 22:57:54
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.93 kb
#include <iostream>
#include <fstream>
#include <vector>
#define MOD 666013

using namespace std;

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

vector <int> v[MOD];

int fnd (int x)
{
    int lst=x%MOD;
    for (int i=0;i<v[lst].size();i++)
        if (v[lst][i]==x) return i;
    return v[lst].size();
}
void inserare (int x)
{
    int lst=x%MOD;
    if (fnd(x)==v[lst].size())
        v[lst].push_back(x);
}
void stergere (int x)
{
    int lst=x%MOD;
    if (fnd(x)!=v[lst].size())
        v[lst].erase(v[lst].begin()+fnd(x));
}
int main()
{
    int n,op,x;
    in>>n;
    while (n--)
    {
        in>>op>>x;
        if (op==1)
        {
            inserare (x);
            continue;
        }
        if (op==2)
        {
            stergere (x);
            continue;
        }
        if (fnd(x)!=v[x%MOD].size()) out<<1<<'\n';
        else out<<0<<'\n';
    }
    return 0;
}