Cod sursa(job #2894819)

Utilizator cosminnnnnnnaDuca Cosmina cosminnnnnnna Data 28 aprilie 2022 13:42:23
Problema Hashuri Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.01 kb
#include <iostream>
#include <fstream>
#include <vector>

#define val  668821
using namespace std;


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

vector <int> M[val];

vector <int> :: iterator check (int x){
    int l = x % val;
    vector <int> :: iterator pos;
    for  (pos = M[l].begin(); pos != M[l].end(); pos++)
        if(*pos == x)
            return pos;
    return M[l].end();
}

void insert (int x){
    int l = x % val;
    if (check(x) == M[l].end())
        M[l].push_back(x);
}


void clear (int x) {
    int l = x % val;
    vector<int>::iterator pos;
    pos = check(x);
    if (pos != M[l].end())
        M[l].erase(pos);

}


int main() {
    int N, operatie, parametru;
    fin >> N;
    for (int i=0; i<N; i++) {
        fin >> operatie >> parametru;
        if (operatie == 1)
            insert(parametru);
        else if (operatie == 2)
            clear(parametru);
        else if (operatie == 3)
            fout << (check(parametru) != M[parametru % val].end());
    }

    return 0;
}