Cod sursa(job #1118312)

Utilizator MutescuMutescu Alexandru Mutescu Data 24 februarie 2014 09:58:31
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include <cstdio>
#include <algorithm>
#include <vector>
#define ms 599110
using namespace std;
unsigned long n,i,nr,j,si,ty;
int caz;
long p=-1;
vector <unsigned long> v[ms+7];
void ins(unsigned 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 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 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)printf("0\n");
    else printf("1\n");
}
int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    scanf("%ld",&n);
    for(i=1;i<=n;++i)
    {scanf("%d %lu",&caz,&nr);
    if(caz==1){
        ins(nr);}
            else {
                if(caz==2){
                    ers(nr);}
                        else{if(caz==3)
                                tr(nr);}
    }
    }


    return 0;

}