Cod sursa(job #2059242)

Utilizator zeboftwAlex Mocanu zeboftw Data 6 noiembrie 2017 20:05:21
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.06 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin  ("hashuri.in");
ofstream fout ("hashuri.out");

const int MOD = 666013;
vector<int> G[MOD+5];

inline vector<int>::iterator find_value (int x){
    int lista = x % MOD;

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

inline void insert_value (int x) {
    int lista = x % MOD;

    if(find_value(x) == G[lista].end())
        G[lista].push_back(x);
}

inline void erase_value (int x) {
    int lista = x % MOD;
    vector<int>::iterator it = find_value(x);

    if (it != G[lista].end())
        G[lista].erase(it);
}

int main()
{
    int n, op, x;

    fin >> n;

    while (n) {
        fin >> op >> x;
        n--;
        if (op == 1){
            insert_value(x);
            continue;
        }
        if (op == 2){
            erase_value(x);
            continue;
        }
        fout << (find_value(x) != G[x % MOD].end()) << '\n';
    }

    return 0;
}