Cod sursa(job #1982077)

Utilizator hanganflorinHangan Florin hanganflorin Data 17 mai 2017 17:43:13
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.11 kb
#include <fstream>
#include <cstdio>
#include <vector>
#define MOD 666013
using namespace std;


FILE* is=fopen("hashuri.in", "r");
FILE* os=fopen("hashuri.out", "w");

int n, op, x;
vector<int> G[MOD];
vector<int>::iterator find_value(int x);
void add_value(int x);
void remove_value(int x);

int main()
{
    fscanf(is, "%d", &n);
    for ( int i = 0; i < n; ++i )
    {
        fscanf(is, "%d %d", &op, &x);
        if ( op == 1 )
            add_value(x);
        else if ( op == 2 )
            remove_value(x);
        else
            fprintf(os, "%d\n", find_value(x) != G[x%MOD].end() );
    }
    return 0;
}
vector<int>::iterator find_value(int x)
{
    int rest = x % MOD;
    for ( auto it = G[rest].begin(); it != G[rest].end(); it++)
        if ( *it == x )
            return it;
    return G[rest].end();
}
void add_value(int x)
{
    int rest = x % MOD;
    if ( find_value(x) == G[rest].end() )
        G[rest].push_back(x);
}
void remove_value(int x)
{
    int rest = x % MOD;
    auto it = find_value(x);
    if ( it != G[rest].end() )
        G[rest].erase(it);
}