Cod sursa(job #2037606)

Utilizator BotzkiBotzki Botzki Data 12 octombrie 2017 16:21:40
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <cstdio>
#include <vector>
#include <set>

using namespace std;

const int M=666013;

vector < set <int> > T;
set <int>::iterator it;

int h(int key){
  return key%M;
}

int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);
    int n;
    int op,x;
    scanf("%d",&n);
    T.resize(M+5);
    for(int y=1;y<=n;++y)
    {
      scanf("%d%d",&op,&x);
      int key=h(x);
      if(op==1)
        T[key].insert(x);
      else
      {
        it=T[key].find(x);
        if(op==2){
          if(it != T[key].end())
            T[key].erase(it);
        }
        if(op==3){
            if(it != T[key].end())
              printf("1\n");
            else
              printf("0\n");
        }
      }
    }
    return 0;
}