Cod sursa(job #2747036)

Utilizator Teodora67IDKIDKIDKDIKD Teodora67 Data 28 aprilie 2021 19:40:59
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include <fstream>
#include <vector>
 
using namespace std;
 
ifstream fin ("hashuri.in");
ofstream fout ("hashuri.out");
 
const int mod1 = 66667;
vector < int > H[mod1];


void Add(int x) {
 
    int i = x % mod1;
    H[i].push_back(x); //introduc valoare in vectorul portrivit
}
 
void Erase(int x) {
 
    int i = x % mod1; //determin in ce vector se afla valoarea si sterg
    for ( size_t w = 0; w < H[i].size(); ++w)
            if ( H[i][w] == x) {
                H[i].erase(H[i].begin() + w);
                return;
            }
}
 
bool Query(int x) {
 
    int i = x % mod1;
    for ( size_t w = 0; w < H[i].size(); ++w)
            if ( H[i][w] == x) {
                return true;
            }
    return false;
} 
 
int main() {
 
    int cer,x;
    int t;
    fin >> t;
    for ( ; t > 0; --t) {
        fin >> cer >> x;
        if ( cer == 1)
            Add(x);
        else
            if ( cer == 2)
                Erase(x);
        else
            fout << Query(x) << "\n";
    }
}