Cod sursa(job #1880071)

Utilizator EuAlexOtaku Hikikomori EuAlex Data 15 februarie 2017 13:58:58
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.9 kb
#include <cstdio>
#include <vector>

using namespace std;

const int MOD = 666013;

vector <int> H[MOD + 5];

int find_x(int x) {
    int lista;
    lista = x % MOD;
    for(int i = 0; i < H[lista].size(); ++ i) {
        if(x == H[lista][i]) {
            return i;
        }
    }
    return -1;
}

void tip1(int x) {
    if(find_x(x) == -1) {
        H[x % MOD].push_back(x);
    }
}

void tip2(int x) {
    int poz = find_x(x);
    if(poz != -1) {
        H[x % MOD].erase(H[x % MOD].begin() + poz);
    }
}

void tip3(int x) {
    printf("%d\n", find_x(x) != -1);
}

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

    int t, tip, x;
    scanf("%d", &t);

    while(t--) {
        scanf("%d%d", &tip, &x);
        if(tip == 1)    tip1(x);
        else if(tip == 2)   tip2(x);
        else tip3(x);
    }

    return 0;
}