Cod sursa(job #1587533)

Utilizator LuurAndrei Florea Luur Data 2 februarie 2016 11:09:57
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.85 kb
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
long long E;
long N;
int op;
vector < int > v[393242];
typedef vector <int> v_it;
long h(long long x){
    return x % 393241;
}
void INSERT(long x){
   if (find(v[h(x)].begin(), v[h(x)].end(), x) == v[h(x)].end()){
       v[h(x)].push_back(x);
   }
}
void DELETE(long x){
  v_it::iterator y = find(v[h(x)].begin(), v[h(x)].end(), x);
  if (y  != v[h(x)].end()){
       v[h(x)].erase(y);
   }
}
int main()
{
   freopen("hashuri.in","r", stdin);
   freopen("hashuri.out","w", stdout);

   scanf("%ld",&N);
   for(; N; --N){
     scanf("%d%lld",&op, &E);
     if (op == 1) INSERT(E);
     if (op == 2) DELETE(E);
     if (op == 3) {
            printf("%d\n", find(v[h(E)].begin(), v[h(E)].end(), E) == v[h(E)].end() ? 0 : 1 );
     }
   }
    return 0;
}