Cod sursa(job #2051033)

Utilizator mirunafrancescaMiruna mirunafrancesca Data 28 octombrie 2017 14:22:50
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.97 kb
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define mod 666013

vector <int> v[666013];

void hash1(int x)
{
    v[x%mod].push_back(x);
    vector <int> ::iterator it=v[x%mod].begin();
}

int caut(int x)
{
    int l = x%mod;

    vector<int>::iterator p = find(v[l].begin(),v[l].end(), x);
    if(p == v[l].end())
            return 0;

    return 1;
}

void c2(int x)
{
    v[x%mod].erase(find(v[x%mod].begin(),v[x%mod].end(),x));
}

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

    int n, x, k, c;

    cin>>n;
    for(int i=1; i<=n; i++)
     {
         scanf("%d %d \n", &c, &x);

         k=caut(x);
         switch(c)
         {
            case 1: if(k==0) hash1(x);
            break;

            case 2: if(k==1) c2(x);
            break;

            case 3: printf("%d \n",k);

         }

     }

    return 0;
}