Cod sursa(job #1848607)

Utilizator wilson182Alexandrina Panfil wilson182 Data 16 ianuarie 2017 12:37:33
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.97 kb
#include <stdio.h>
#include <vector>
using namespace std;
#define M 666013
vector<int> h[M];
 
inline vector<int>::iterator find_value(int x)
{
    int ord = x % M;
    vector<int>::iterator it;
 
    for (it = h[ord].begin(); it != h[ord].end(); ++it)
        if (*it == x)
            return it;
    return h[ord].end();
}
 
inline void add(int x)
{
    int ord = x % M;    
    if (find_value(x) == h[ord].end())
        h[ord].push_back(x);
}
inline void remove(int x)
{
    int ord = x % M;
    vector<int>::iterator it = find_value(x);
     
    if (it != h[ord].end())
        h[ord].erase(it);
}
 
int main()
{
    int x, y, n;
     
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
 	scanf("%d", &n);
    while(n--)
    {
        scanf("%d %d", &x, &y);
        if (x == 1)add(y);
        if (x == 2)remove(y);
        if (x == 3) printf("%d\n", find_value(y) != h[y % M].end());
    }
 
    return 0;
}