Cod sursa(job #2097307)

Utilizator DianaVelciovVelciov Diana DianaVelciov Data 30 decembrie 2017 21:47:32
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.83 kb
#include <fstream>
#include <vector>

using namespace std;

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

const int MOD = 666013;
vector <int> G[MOD + 2];
int N, 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;
}