Cod sursa(job #1706191)

Utilizator mateigabionumatei gabi mateigabionu Data 21 mai 2016 21:04:19
Problema Hashuri Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 1.28 kb
#include <iostream>
#include <fstream>
 
using namespace std;
 
#define ma 666613
ifstream f("hashuri.in");
ofstream g("hashuri.out");
 
struct nod
{
    int info;
    nod *urm;
}*v[ma];
 
int n, a, b;
 
int que( int p, int b )
{
    nod*it = v[p];
    while( it )
    {
        if( it->info == b )
            return 1;
        it = it->urm;
    }
    return 0;
}
 
void add( int p, int b )
{
    nod *nou;
    nou = new nod;
    nou->info = b;
    nou->urm = v[p];
    v[p] = nou;
}
 
void del( int p, int b )
{
    nod *p1, *p2;
    p1 = v[p];
    if(p1->info == b )
    {
        v[p] = p1->urm;
        delete p1;
    }
    else
    {
        p1 = p1->urm;
        p2 = v[p];
        while( p2->info != b )
        {
            p2 = p1;
            p1 = p1->urm;
        }
        p2->urm = p1->urm;
        p1->urm = NULL;
        delete p1;
    }
}
 
int main()
{
    f >> n;
    for( int i=1; i<=n; ++i )
    {
        f >> a >> b;
        int p = b%ma;
        int x = que(p, b);
        if( a == 3 )
        {
            g << x << '\n';
        }
        else if( a == 1 && x == 0 )
        {
            add(p, b);
        }
        else if( x == 1 )
        {
            del(p, b);
        }
 
    }
    return 0;
}