Cod sursa(job #2657367)

Utilizator Asgari_ArminArmin Asgari Asgari_Armin Data 10 octombrie 2020 13:46:30
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.05 kb
#include <stdio.h>
#include <vector>

using namespace std;

const int NMAX = 1e6;
const int MOD = 666013;

vector <int> v[MOD];

void add_hash( int x ){
  int i = 0, code = x % MOD;
  while( i < v[code].size() && x != v[code][i] )
    ++i;
  if( i == v[code].size() )
    v[code].push_back(x);
}

bool search_hash( int x ){
  int i = 0, code = x % MOD;
  while( i < v[code].size() && x != v[code][i] )
    ++i;
  return i < v[code].size();
}

void erase_hash( int x ){
  int i = 0, code = x % MOD;
  while( i < v[code].size() && x != v[code][i] )
    ++i;
  if( i < v[code].size() )
    v[code].erase(v[code].begin() + i);
}


int main() {
  int n, op, x;
  FILE *fin, *fout;
  fin = fopen( "hashuri.in", "r" );
  fout = fopen( "hashuri.out", "w" );
  fscanf( fin, "%d", &n );
  while( n-- ){
    fscanf( fin, "%d%d", &op, &x );
    if( op == 1 )
      add_hash(x);
    else if( op == 2 )
      erase_hash(x);
    else
      fprintf( fout, "%d\n", search_hash(x) );
  }
  fclose( fin );
  fclose( fout );
   return 0;
}