Cod sursa(job #2192536)

Utilizator firutibogdanFiruti Bogdan-Cristian firutibogdan Data 6 aprilie 2018 14:46:09
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.14 kb
#include <fstream>
#include <vector>

using namespace std;

#define size 666013
vector<int> map[size];


vector<int>::iterator find_val(int x) {
  vector<int>::iterator it;
  for(it = map[x % size].begin(); it != map[x % size].end(); it++) {
    if (*it == x) {
      return it;
    }
  }
  return map[x % size].end();
}

void erase_val(int x) {
  vector<int>::iterator it = find_val(x);
  if (it != map[x % size].end()) {
    map[x % size].erase(it);
  }
}

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

  int n, t, x;

  fin >> n;
  for (int i = 0; i < n; ++i) {
    fin >> t >> x;
    vector<int>::iterator it;
     switch (t) {
       case 1: if (find_val(x) == map[x % size].end()) {
                  map[x % size].push_back(x);
               }
               continue;
       case 2:
               erase_val(x);
               continue;
       case 3:
                it = find_val(x);
                if (it != map[x % size].end()) {
                  fout << "1\n";
                } else {
                  fout << "0\n";
                }
                continue;
     }
  }

  fin.close();
  fout.close();
  return 0;
}