Cod sursa(job #2210861)

Utilizator alexsandulescuSandulescu Alexandru alexsandulescu Data 8 iunie 2018 14:18:05
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.82 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("hashuri.in");
ofstream g("hashuri.out");

const int CONST = 666013;
int N, cer, x;
vector<int> a[CONST + 1];

inline void find_and_delete(int x) {
    for(auto it = a[x % CONST].begin(); it != a[x % CONST].end(); it++) {
        if(*it == x) {
            a[x % CONST].erase(it);
            break;
        }
    }
}

inline bool is_in(int x) {
    for(auto it = a[x % CONST].begin(); it != a[x % CONST].end(); it++) {
        if(*it == x) return true;
    }
    return false;
}
int main() {

    f >> N;
    for(int i = 1; i <= N; i++) {
        f >> cer >> x;
        if(cer == 1 && !is_in(x))
            a[x % CONST].push_back(x);
        else if(cer == 2)
            find_and_delete(x);
        else if(cer == 3)
            g << is_in(x) << "\n";
    }
    return 0;
}