Cod sursa(job #2246358)

Utilizator alex.cojocaruAlex Cojocaru alex.cojocaru Data 26 septembrie 2018 23:34:22
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <iostream>
#include <vector>
#include <stdio.h>

#define MOD 666013

using namespace std;

vector <int> mat [ MOD + 1 ] ;

int H (int x ) {
  return x % MOD ;
}

void deleteh (int i, int x ) {
  vector <int>::iterator j ;
  for (j = mat[i].begin() ; j != mat[i].end() && *j != x ; j++ ) ;
  if (j != mat[i].end())
    mat[i].erase(j) ;
}

bool exist (int i, int x ) {
  vector <int>::iterator j ;
  for ( j = mat[i].begin() ; j != mat[i].end() && *j != x ; j++ ) ;
    //printf ("%d ", *j ) ;
  //printf ("\n") ;
  if (j != mat[i].end() )
    return true ;
  return false ;
}

int main() {

  FILE *fin, *fout ;
  fin = fopen ("hashuri.in", "r" ) ;
  fout = fopen ("hashuri.out", "w" ) ;
  int n, op, x, i ;
  fscanf (fin, "%d", &n ) ;
  for (i = 0 ; i < n ; i++ ) {
    fscanf (fin, "%d%d", &op, &x ) ;
    switch (op) {
      case 1 : {
        if (exist (H(x), x ) == false )
          mat[H(x)].push_back(x) ;
        break ;
      }
      case 2 : {
        deleteh (H(x), x ) ;
        break ;
      }
      case 3 : {
        fprintf (fout, "%d\n", exist(H(x), x) ) ;
        break ;
      }
    }
  }
  return 0;
}