Cod sursa(job #1050247)

Utilizator PsychoAlexAlexandru Buicescu PsychoAlex Data 8 decembrie 2013 13:53:20
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 4.11 kb
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>

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

//struct nod
//{
//    int val;
//    nod *next;
//};

int n;

//nod *prim[666014];

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

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

        if(x == 1)
        {
            if(hashuri[y%666013].size())
            {
//                nod *val = prim[y%666013];
                bool found = false;
                for(int i = 0; i < hashuri[y%666013].size(); i++)
                {
                    if(hashuri[y%666013][i] == y)
                    {
                        found = true;
                        break;
                    }
                }
//                while(val)
//                {
//                    if(val->val == y)
//                    {
//                        found = true;
//                        break;
//                    }
//                    val = val->next;
//                }
                if(!found)
                {
//                    nod *newNod = new nod;
//                    newNod->val = y;
//                    newNod->next = prim[y%666013];
                    hashuri[y%666013].push_back(y);
                }
            }
            else
            {
//                prim[y%666013] = new nod;
//                prim[y%666013]->val = y;
//                prim[y%666013]->next = NULL;
                    hashuri[y%666013].push_back(y);
            }
        }
        else
            if(x == 2)
            {
                if(hashuri[y%666013].size())
                {
//                    nod *val = prim[y%666013];

//                    if(val->val == y)
//                    {
//                        prim[y%666013] = val->next;
//                        delete val;
//                        continue;
//                    }

                    for(int i = 0; i < hashuri[y%666013].size(); i++)
                    {
                        if(hashuri[y%666013][i] == y)
                        {
                            hashuri[y%666013][i] = hashuri[y%666013].back();
                            hashuri[y%666013].pop_back();
                        }
                    }

//                    while(val->next)
//                    {
//                        if(val->val == y)
//                        {
//                            val->next->next = val->next;
//                            delete val;
//                            break;
//                        }
//                        val = val->next;
//                    }
                }
            }
            else
            {
                if(hashuri[y%666013].size())
                {
//                    nod *val = prim[y%666013];
                    bool found = false;

                    for(int i = 0; i < hashuri[y%666013].size(); i++)
                    {
                        if(hashuri[y%666013][i] == y)
                        {
                            found = true;
                            fout<<1<<'\n';
//                            std::cout<<1<<'\n';
                            break;
                        }
                    }

//                    while(val)
//                    {
//                        if(val->val == y)
//                        {
//                            fout<<1<<'\n';
//                            std::cout<<1<<'\n';
//                            found = true;
//                            break;
//                        }
//                        val = val->next;
//                    }
                    if(!found)
                    {
                        fout<<0<<'\n';
//                        std::cout<<0<<'\n';
                    }
                }
                else
                {
                    fout<<0<<'\n';
//                    std::cout<<0<<'\n';
                }
            }
    }
}

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