Cod sursa(job #2193174)

Utilizator kitzTimofte Bogdan kitz Data 9 aprilie 2018 10:01:47
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.35 kb
#include <stdio.h>
#include <vector>
#define SEED 666013

using namespace std;
int N;
vector<int> valuesSet[SEED];

vector<int>::iterator search(int value, int listIndex) {
    vector<int>::iterator it;

    for (it = valuesSet[listIndex].begin(); it != valuesSet[listIndex].end(); it++) {
        if (*it == value) { return it; }
    }

    return valuesSet[listIndex].end();
}

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

    int operation, parameter;
    scanf("%d", &N);

    int counter = 0;
    while ( N > 0) {
        scanf("%d %d", &operation, &parameter);
        int listIndex = parameter % SEED;
        if (operation == 1) {
            // insert into set
            if (search(parameter, listIndex) == valuesSet[listIndex].end()) {
                valuesSet[listIndex].push_back(parameter);
            }
        }
        if (operation == 2) {
            // delete from set
            vector<int>::iterator position = search(parameter, listIndex);
            if (position != valuesSet[listIndex].end()) {
                valuesSet[listIndex].erase(position);
            }
        }
        if (operation == 3) {
            // query the set for parameter's existence
            printf("%d\n", search(parameter, listIndex) != valuesSet[listIndex].end());
            
        }
        N --; 
    }
    return 0;
}