Cod sursa(job #1766421)

Utilizator valentinoMoldovan Rares valentino Data 27 septembrie 2016 22:08:50
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.05 kb
#include <list>
#include <fstream>
#include <iostream>
#define MOD 666013

using namespace std;

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

list < int > mylist[MOD];
int n;

inline list <int>:: iterator find_value(int x)
{
    x = x % MOD;
    for(list<int>::iterator it = mylist[x].begin(); it != mylist[x].end(); ++it)
    {
        if(*it == x) return it;
    }
    return mylist[x].end();
}

inline void insert_list(int x)
{
    x = x % MOD;
    if(find_value(x) == mylist[x].end())
    {
        mylist[x].push_back(x);
    }
}

inline void delete_list(int x)
{
    x = x % MOD;
    list <int>::iterator it = find_value(x);
    if(it != mylist[x].end())
    {
        mylist[x].erase(it);
    }
}

inline void search_list(int x)
{
    g << (find_value(x) != mylist[x].end()) << '\n';
}

int main()
{
    int op, x;
    f >> n;
    for(int i = 1; i <= n; ++i)
    {
        f >> op >> x;
        if(op == 1) insert_list(x);
        else if(op == 2) delete_list(x);
        else search_list(x);
    }
}