Cod sursa(job #2904840)

Utilizator andreiiorgulescuandrei iorgulescu andreiiorgulescu Data 18 mai 2022 09:53:41
Problema Hashuri Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.84 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int MOD = 666014;
vector <int> G[MOD + 2];
int N;
int p, nr;

int Find(int Value)
{
  int List = Value % MOD;
  for(int i = 0; i < (int)G[List].size(); ++i)
    if(G[List][i] == Value)
      return i;
  return -1;
}

void Insert(int Value)
{
  int List = Value % MOD;
  if(Find(Value) == -1)
    G[List].push_back(Value);

}

void Delete(int Value)
{
  int List = Value % MOD,Pos = Find(Value);
  if(Pos != -1)
    G[List].erase(G[List].begin() + Pos);
}

int main()
{
    in >> N;
    for(int i = 1; i <= N; ++i){
      in >> p >> nr;
      if(p == 1)
        Insert(nr);
      else if(p == 2)
        Delete(nr);
      else
          out << (Find(nr) != -1) << "\n";
    }
    return 0;
}