Cod sursa(job #1051063)

Utilizator AlexNiuclaeNiculae Alexandru Vlad AlexNiuclae Data 9 decembrie 2013 18:02:12
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.91 kb
#include <cstdio>
#include <vector>
#define MOD 666013
#define pb push_back

using namespace std;

vector <int> h[MOD];
vector <int>:: iterator it;
int i,n,op,x,ind;

vector <int>::iterator find(int x)
 {
     for (it=h[ind].begin();it!=h[ind].end();it++) if (*it==x) return it;
     return it;
 }

 void insert(int x)
  {
      if (it==h[ind].end()) h[ind].pb(x);
  }

void erase(int x)
  {
      if (it!=h[ind].end()) h[ind].erase(it);
  }

void write(int x)
 {
     if (it!=h[ind].end()) printf("1\n");
         else printf("0\n");
 }



int main()
{
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);

    scanf("%d",&n);
    for (i=1;i<=n;i++)
     {
         scanf("%d %d", &op, &x);
         ind=x%MOD;
         it=find(x);

         if (op==1) insert(x);
          else if (op==2) erase(x);
           else write(x);

     }



    return 0;
}