Cod sursa(job #1550065)

Utilizator CodrutLemeniCodrut Lemeni CodrutLemeni Data 13 decembrie 2015 09:49:10
Problema Hashuri Scor 100
Compilator c Status done
Runda Arhiva educationala Marime 1.08 kb
#include <stdio.h>
#include <stdlib.h>
#define N 666013
#define M 1000000

struct{
    int val,prec;
}v[M];
int h[N];
int lenv;
int poz;

int cauta(int nr,int rest){
    poz=h[rest];

    do{
        if(v[poz].val==nr){
            return 1;
        }
        poz=v[poz].prec;
    }while(poz);
    return 0;
}

void op_1(int nr){
    int rest=nr%N,t;

    t=cauta(nr,rest);
    if(t==0){
        v[lenv].val=nr;
        v[lenv].prec=h[rest];
        h[rest]=lenv;
        lenv++;
    }


}

void op_2(int nr){
    int rest=nr%N,t;

    t=cauta(nr,rest);
    if(t==0){
        return;
    }else{
        v[poz].val=-1;
    }

}

int main(){
    int i,n,nr,op;
    int rest;

    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%d %d",&op,&nr);
        if(op==1){
            op_1(nr);
        }else if(op==2){
            op_2(nr);
        }else{
            rest=nr%N;
            printf("%d\n",cauta(nr,rest));
        }
    }

    return 0;
}