Cod sursa(job #1760775)

Utilizator andrei_diaconu11Andrei C. Diaconu andrei_diaconu11 Data 21 septembrie 2016 11:14:49
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.97 kb
#include <stdio.h>
using namespace std;
#define MOD 673152

int liste[MOD], next[1000000], h[1000000];

int main()
{

  int n, i, l, u, op, x, j;
  FILE *fi=fopen("hashuri.in", "r"), *fo=fopen("hashuri.out", "w");
  fscanf(fi, "%d", &n);
  l=1;
  for(i=0;i<n;i++){
    fscanf(fi, "%d%d", &op, &x);
    switch(op){
      case 1:
        for(j=liste[x%MOD];j!=0 && h[j]!=x;j=next[j]);
        if(h[j]!=x){
          h[l]=x;
          next[l]=liste[x%MOD];
          liste[x%MOD]=l;
        }
        l++;break;
      case 2:
        if(h[liste[x%MOD]]==x)
          liste[x%MOD]=next[liste[x%MOD]];
        else{
          for(j=liste[x%MOD];j!=0 && h[j]!=x;j=next[j])
            u=j;
          if(h[j]==x)
            next[u]=next[j];
        }
        break;
      case 3:
        for(j=liste[x%MOD];j!=0 && h[j]!=x;j=next[j]);
        if(h[j]==x)
          fprintf(fo, "1\n");
        else
          fprintf(fo, "0\n");
        break;
    }
  }
  fclose(fi);
  fclose(fo);
  return 0;
}