Cod sursa(job #2880209)

Utilizator anne_marieMessner Anne anne_marie Data 29 martie 2022 15:20:43
Problema Hashuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <fstream>
#include <vector>
#define M 1000117
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");

vector <int> h[M];

inline vector<int> :: iterator cauta(int x) {
    int rest = x % M;
    vector <int> :: iterator it = h[rest].begin(), sf = h[rest].end();
    for(; it !=sf ; it++)
        if(*it==x) return it;
    return sf;
}



inline void adaug(int y) {
    int rest = y % M;
    if(cauta(y) == h[rest].end()) { h[rest].push_back(y);}
}



inline void sterg(int x)
{   int rest = x % M;
    vector <int> :: iterator it=cauta(x);
    if(it != h[rest].end()) h[rest].erase(it);
}
int main() {

    int n;
    int x, y;
    fin >> n;
    while(n--){
        fin >> x >> y;
        if( x == 1 ) { adaug(y);}
        else
        if( x == 2 ) { sterg(y);}
        else
        if( x == 3 ) { if(cauta(y) == h[y % M].end()) fout << "0\n"; else fout << "1\n";}
    }

    return 0;
}