Cod sursa(job #2554859)

Utilizator etienAndrone Stefan etien Data 23 februarie 2020 14:35:47
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.08 kb
#include<fstream>
#include<vector>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int n,i,op,x,rest;
vector<int>r[666014];
int main()
{
    fin>>n;
    for(i=1; i<=n; i++)
    {
        fin>>op>>x;
        rest=x%666013;
        int dim=r[rest].size();
        if(op==1)
            {
            bool found=false;
            for(int j=0; j<dim; j++)
                if(r[rest][j]==x)
                {
                    found=true;
                }
            if(!found)
                r[rest].push_back(x);}
        else if(op==2)
        {
            for(int j=0; j<dim; j++)
                if(r[rest][j]==x)
                {
                    swap(r[rest][j],r[rest][dim-1]);
                         r[rest].pop_back();
                    break;
                }
        }
        else
        {
            bool found=false;
            for(int j=0; j<dim; j++)
                if(r[rest][j]==x)
                {
                    found=true;
                }
            fout<<found<<"\n";
        }
    }
}