Cod sursa(job #2624632)

Utilizator ioanapintilie07Pintilie Ioana ioanapintilie07 Data 5 iunie 2020 01:32:59
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

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

const int prim = 666013;

int n;
vector<int> hashh[prim];

bool caut(int x) {
    int lista = x % prim;
    for(auto &i : hashh[lista])
        if(i == x)
            return true;
    return false;
}

bool inserez(int x) {
    int lista = x % prim;
    hashh[lista].push_back(x);
}


bool sterg(int x) {
    int lista = x % prim;
    for(auto &it:hashh[lista]) {
        if (it == x) {
            it = hashh[lista][hashh[lista].size() - 1];
            hashh[lista].pop_back();
        }
    }
}
int main() {
    int n, instr, x;
    fin >> n;
    for(int i = 0; i < n; ++i) {
        fin >> instr >> x;
        if(instr == 1)
            inserez(x);
        else if(instr == 2)
            sterg(x);
        else
            fout << caut(x) << "\n";
    }
    return 0;
}