Cod sursa(job #2768812)

Utilizator BlaugranasEnal Gemaledin Blaugranas Data 12 august 2021 11:44:36
Problema Hashuri Scor 100
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include<stdio.h>
#include<stdlib.h>
#define M 666013
typedef struct O {
    int I;
    struct O *U;
}N;
int n,y,x,z;
N *h[M],*p,*q;
int main()
{
    freopen("hashuri.in","r",stdin),freopen("hashuri.out","w",stdout),scanf("%d",&n);
    while(n--) {
        scanf("%d%d",&x,&y),z=y%M;
        for(p=q=h[z];p&&p->I!=y;q=p,p=p->U);
        if(x==1&&!p) {
            p=(N*)malloc(sizeof(N));
            p->U=h[z],p->I=y,h[z]=p;
        } else if(x==2&&p)
            if(q==p)
                h[z]=h[z]->U;
            else
                q->U=p->U;
        else if(x==3)
            printf("%d\n",p?1:0);
    }
    return 0;
}