Cod sursa(job #1442214)

Utilizator DrumeaVDrumea Vasile DrumeaV Data 24 mai 2015 18:22:52
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.4 kb
#include <bits/stdc++.h>
const int Mod = 1111111;
using namespace std;

int N;
vector<int> T[Mod];

inline void ins(int x)
{
    int value = x % Mod;
    bool ok = false;
    vector<int>::iterator i;

    for (i = T[value].begin();i != T[value].end();i++)
        if (*i == x)
        {
            ok = true;
            break;
        }
    if (!ok) T[value].push_back(x);
}

inline void del(int x)
{
    int value = x % Mod;
    vector<int>::iterator i;

    for (i = T[value].begin();i != T[value].end();i++)
        if (*i == x)
        {
            T[value].erase(i);
            break;
        }
}

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

    while (--N)
    {
        int op,x;
        scanf("%d %d",op,x);
         if (op == 1)
         {
             ins(x);
             continue;
         }
         if (op == 2)
         {
             del(x);
             continue;
         }
         int value = x % Mod;
         vector<int>::iterator i;
         bool ok = false;

              for (i = T[value].begin();i != T[value].end();i++)
                  if (*i == x)
                   {
                        ok = true;
                        printf("%d",1);
                        break;
                   }
              if (!ok) printf("%d",0);
     }
     return 0;
}