Cod sursa(job #1150890)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 23 martie 2014 17:47:32
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include <fstream>
#include <cstdio>
#include <vector>
#define MOD 666013
using namespace std;
ifstream ff("hashuri.in");
ofstream g("hashuti.out");
vector< int> v[MOD];
int N,i,f,x,p,j;
int search(int x)
{
    p=x%MOD;
    for(j=0;j<v[p].size();j++)
    {
        if(v[p][j]==x)
            return 1;
    }
    return 0;
}
void sterge(int x)
{
    p=x%MOD;
    if(v[p].size()!=0)
    {
        for(j=0;j<v[p].size();j++)
        {
            if(v[p][j]==x)
                v[p].erase(v[p].begin()+j),j=v[p].size();
        }
    }
}
int main()
{
   // freopen("hashuri.in","r",stdin);
   // freopen("hashuri.out","w",stdout);
    ff>>N;
    for(i=1;i<=N;i++)
    {
        ff>>f>>x;
        if(f==1)
        {
            if(search(x)==0)
                p=x%MOD,v[p].push_back(x);
        }
        else
        {
            if(f==2)
            {
                sterge(x);
            }
            else
            {
                g<<search(x)<<"\n";
            }
        }
    }
    return 0;
}