Cod sursa(job #2657348)

Utilizator AlexNicuNicu Alexandru AlexNicu Data 10 octombrie 2020 13:33:04
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.07 kb
#include <fstream>
#include <vector>
#include <stdio.h>
using namespace std;

#define MAX_N 1000000
#define MOD 666013

ifstream cin ( "hashuri.in" );
ofstream cout ( "hashuri.out" );

vector<int> myHash[MOD];
bool cauta( int x ) {
  int cod = x % MOD;
  unsigned int i = 0;
  while ( i < myHash[cod].size() && myHash[cod][i] != x )
    i++;
  return i < myHash[cod].size();
}

void adauga( int x ) {
  int cod = x % MOD;
  unsigned int i = 0;
  while ( i < myHash[cod].size() && myHash[cod][i] != x )
    i++;
  if ( i == myHash[cod].size() )
    myHash[cod].push_back(x);
}

void sterge( int x ) {
  int cod = x % MOD;
  unsigned int i = 0;
  while ( i < myHash[cod].size() && myHash[cod][i] != x )
    i++;
  if ( i < myHash[cod].size() )
    myHash[cod].erase(myHash[cod].begin() + i);
}

int main() {
    int n, op, x, i;
    cin >> n;
    for ( i = 1; i <= n; i++ ) {
      cin >> op >> x;
      if ( op == 1 )
        adauga(x);
      else if ( op == 2 )
        sterge(x);
      else
        cout << cauta(x) << "\n";
    }
    return 0;
}