Cod sursa(job #2632273)

Utilizator stefanvoicaVoica Stefan stefanvoica Data 2 iulie 2020 17:27:04
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("hashuri.in");
ofstream fout("hashuri.out");
const int val=700571;
vector<int> v[val];

bool gasit (int x)
{
    int rest=x%val;
    for (int i=0;i<v[rest].size();++i)
        if (v[rest][i]==x)
            return 1;
    return 0;
}


void adauga (int x)
{
    if (gasit(x)==0)
        v[x%val].push_back(x);
}

void sterge (int x)
{
    int rest=x%val;
    for (int i=0;i<v[rest].size();i++)
        if (v[rest][i]==x)
    {
        v[rest].erase(v[rest].begin()+i);
        return;
    }
}


int main()
{
    int t,x,q;
    fin>>q;
    for (;q>0;q--)
    {
        fin>>t>>x;
        if (t==1)
        adauga (x);
        else if (t==3)
            fout<<gasit(x)<<'\n';
        else    sterge (x);
    }
    return 0;
}