Cod sursa(job #1144257)

Utilizator gedicaAlpaca Gedit gedica Data 16 martie 2014 20:10:20
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.36 kb
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

unsigned long long n,i,nr,j,si,ty;
int caz;
long long p=-1;

const int ms= 666013;

vector <unsigned long> v[ms+7];

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

void ins( unsigned long long x )
{
    ty= x%ms;
    p=- 1;
    si= v[ty].size();
    j= 0;
    while(p<0&&j<si)
    {
        if (v[ty][j]==x) p= j;
        ++j;
    }
    if ( p==-1 ) v[ty].push_back(x);
}
void ers(unsigned long long x)
{
    ty= x%ms;
    p= -1;
    si= v[ty].size();
    j= 0;
    while( p<0 && j<si )
    {
        if (v[ty][j]==x) p=j;
        ++j;
    }
    if( p!= -1 ) v[ty].erase( v[ty].begin()+p );
}
void tr(unsigned long long x)
{
    ty= x%ms;
    p= -1;
    si= v[ty].size();
    j= 0;
    while( p==-1 && j<si )
    {
        if (v[ty][j]==x) p=j;
        ++j;
    }
    if( p==-1 ) out << "0" << '\n';
    else out << "1" << '\n';
}
int main()
{
    in >> n;
    for( int i= 1; i<=n; ++i )
    {
        in >> caz >> nr;
        if( caz==1 )
        {
            ins(nr);
        }
        else
        {
            if( caz==2 )
            {
                ers(nr);
            }
            else
            {
                if(caz==3)
                    tr(nr);
            }
        }
    }
    return 0;

}