Cod sursa(job #1649045)

Utilizator maribMarilena Bescuca marib Data 11 martie 2016 12:25:02
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.14 kb
#include <fstream>
#define PRIM 666013
#include <list>

typedef long long ll;

using namespace std;

list <ll> liste[PRIM];

ll x;

int tip, n, found, ind;

list <ll>::iterator it;

int main()
{
    ifstream in("hashuri.in");
    ofstream out("hashuri.out");
    in>>n;
    for(int i = 1; i <= n; ++i){
        found = 0;
        in>>tip>>x;
        ind = x % PRIM;
        if(tip == 1){
            for(it = liste[ind].begin(); it != liste[ind].end(); ++it){
                if(*it == x)
                    found = 1;
            }
            if(!found || liste[ind].empty()) liste[ind].push_back(x);
        }
        if(tip == 2){
            for(it = liste[ind].begin(); it != liste[ind].end(); ++it){
                if(*it == x){
                    liste[ind].erase(it);
                    break;
                }
            }
        }
        if(tip == 3){
            for(it = liste[ind].begin(); it != liste[ind].end(); ++it){
                if(*it == x)
                    found = 1;
            }
            out<<found<<"\n";
        }
    }
    in.close();
    out.close();
    return 0;
}