Cod sursa(job #1700437)

Utilizator cella.florescuCella Florescu cella.florescu Data 10 mai 2016 15:21:57
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.93 kb
#include <cstdio>
#include <vector>
#define MOD 1210883

using namespace std;

vector <int> lst[MOD];

inline vector <int>::iterator myfind(int key){
  int x=key%MOD;
  vector <int>::iterator i=lst[x].begin();
  while(i!=lst[x].end()){
    if(*(i)==key)
      return i;
    ++i;
  }
  return i;
}

inline void myadd(int key){
  if(myfind(key)==lst[key%MOD].end())
    lst[key%MOD].push_back(key);
}

inline void myerase(int key){
  vector <int>::iterator i=myfind(key);
  if(i!=lst[key%MOD].end())
    lst[key%MOD].erase(i);
}

int main()
{
    FILE *fin, *fout;
    int n, i, nr, op;
    fin=fopen("hashuri.in", "r");
    fscanf(fin, "%d", &n);
    fout=fopen("hashuri.out", "w");
    for(i=0; i<n; i++){
      fscanf(fin, "%d%d", &op, &nr);
      if(op==1)
        myadd(nr);
      else if(op==2)
        myerase(nr);
      else
        fprintf(fout, "%d\n", myfind(nr)!=lst[nr%MOD].end());
    }
    fclose(fin);
    fclose(fout);
    return 0;
}