Cod sursa(job #1050262)

Utilizator PsychoAlexAlexandru Buicescu PsychoAlex Data 8 decembrie 2013 14:01:12
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.38 kb
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>

std::ifstream fin("hashuri.in");
std::ofstream fout("hashuri.out");

int n;

std::vector<int> hashuri[666013];

inline int cauta(int &poz, int &val)
{
    for(int i = 0; i < hashuri[poz%666013].size(); i++)
    {
        if(hashuri[poz%666013][i] == val)
        {
            return i;
        }
    }
    return -1;
}

void citire()
{
    int x, y;
    fin>>n;
    for(int i = 0; i < n; i++)
    {
        fin>>x>>y;

        if(x == 1)
        {
            if(cauta(y, y) == -1)
            {
                hashuri[y%666013].push_back(y);
            }
        }
        else
            if(x == 2)
            {
                if(hashuri[y%666013].size())
                {
                    int poz = cauta(y, y);
                    if(poz != -1)
                    {
                        hashuri[y%666013][poz] = hashuri[y%666013].back();
                        hashuri[y%666013].pop_back();
                    }
                }
            }
            else
            {
                if(cauta(y, y) != -1)
                {
                    fout<<1<<'\n';
                }
                else
                {
                    fout<<0<<'\n';
                }
            }
    }
}

int main()
{
    citire();
    return 0;
}