Cod sursa(job #256327)

Utilizator alecmanAchim Ioan Alexandru alecman Data 11 februarie 2009 16:12:31
Problema Hashuri Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.15 kb
#include<cstdio>
#include<vector>

using namespace std;

#define INPUT "hashuri.in"
#define OUTPUT "hashuri.out"
#define MOD 666013

FILE *fin = fopen(INPUT, "r"), *fout = fopen(OUTPUT, "w");

vector<long> Vec[ MOD + 1];

void insert(long Value)
{
  long pozNod = Value % MOD;

  Vec[ pozNod ].push_back(Value);
}

void extract(long Value)
{
  vector<long>::iterator it;
  long pozNod = Value % MOD;

  for(it = Vec[ pozNod ].begin(); it != Vec[ pozNod ].end(); ++it)
  {
    if(*it == Value)
      Vec[ pozNod ].erase(it);

    return;
  }
}

int verify(long Value)
{
  vector<long>::iterator it;
  long pozNod = Value % MOD;

  for(it = Vec[ pozNod ].begin(); it != Vec[ pozNod ].end(); ++it)
  {
    if(*it == Value)
      return 1;
  }

  return 0;
}

int main()
{
  long N, Code, Value;

  fscanf(fin, "%ld", &N);

  for(long i = 0; i < N; ++i)
  {
    fscanf(fin, "%ld %ld", &Code, &Value);
    
    if(Code == 1)
    {
      if(!verify(Value)) insert(Value);
    }
    else
    if(Code == 2)
    {
      if(verify(Value)) extract(Value);
    }
    else
    if(Code == 3)
      fprintf(fout, "%d\n", verify(Value));
  }

  fclose(fin);
  fclose(fout);

  return 0;
}