Cod sursa(job #916354)

Utilizator cont_testeCont Teste cont_teste Data 16 martie 2013 13:27:57
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.19 kb

#include<vector>
#include<algorithm>
#include<cstdio>


#define MOD 660013

FILE *f=fopen("hashuri.in","r");
FILE *g=fopen("hashuri.out","w");

using namespace std;

int n,type;
vector <int> list[MOD];

inline vector<int>::iterator find(int x)
{
    int pos=x%MOD;
    vector<int>::iterator it;

    for(it=list[pos].begin();it!=list[pos].end(); ++it )
        if(*it == x )
        return it;
    return list[pos].end();



}

void insert ( int x )
{

   int pos=x%MOD;
   if(find(x) == list[pos].end())
    list[pos].push_back(x);
}

void erase( int x)
{
    int pos=x%MOD;
    vector <int>::iterator it;
    it=find(x);
    if(it!=list[pos].end())
        list[pos].erase(it);
}

int main( void )
{
    fscanf(f,"%d",&n);

    for(int i(1); i <= n ; ++i )
    {
        int x;
       fscanf(f,"%d%d",&type,&x);
       if(type ==1 )
        {
            insert(x);
            continue;
        }
        if(type == 2)
        {
            erase(x);
            continue;
        }
        if(type == 3 )
        {
            fprintf(g,"%d\n",find(x)!=list[x%MOD].end());
        }
    }
    fclose(f);
    fclose(g);
    return 0;
}