Cod sursa(job #2486891)

Utilizator isa_tudor_andreiAndrei Tudor isa_tudor_andrei Data 3 noiembrie 2019 17:19:10
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.97 kb
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

const int M = 666013;

vector<int> G[M];

vector<int>::iterator find_elem( int x ) {
  vector<int>::iterator it;
  int lista = x % M;

  for( it = G[lista].begin(); it < G[lista].end(); it ++ )
    if( *it == x )
      return it;

  return G[lista].end();
}

void insert_elem( int x ) {
  int lista = x % M;

  if( find_elem(x) == G[lista].end() )
    G[lista].push_back(x);
}

void erase_elem( int x ) {
  int lista = x % M;
  vector<int>::iterator it = find_elem(x);
  if( it != G[lista].end() )
    G[lista].erase(it);
}

int main() {
    int n;
    fin>>n;
    while( n -- ) {
      int op, x;
      fin>>op>>x;
      if( op == 1 )
        insert_elem(x);
      else if( op == 2 )
        erase_elem(x);
      else
        fout<<!( find_elem(x) == G[x % M].end() )<<"\n";
    }
    return 0;
}