Pagini recente » Istoria paginii runda/summer-challenge-2021 | REZULTATE | Profil bogobat | Istoria paginii utilizator/furia_politehnicii | Cod sursa (job #725969)
Cod sursa(job #725969)
#include <fstream>
#include <vector>
using namespace std;
const int MOD = 666013;
vector<int> H[MOD];
inline int h(int x){
return x%MOD;
}
inline vector<int>::iterator _find(int x){
vector<int>::iterator it;
for(it = H[h(x)].begin(); it != H[h(x)].end(); it++)
if(*it == x)
return it;
return it;
}
bool find(int x){
return _find(x) != H[h(x)].end();
}
void add(int x){
if(not find(x))
H[h(x)].push_back(x);
}
void remove(int x){
vector<int>::iterator it = _find(x);
if( it != H[h(x)].end())
H[h(x)].erase(it);
}
int main(){
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
int nCmd, cmd, x;
fin >> nCmd;
for( int i = 0; i < nCmd; i++){
fin >> cmd >> x;
if(cmd == 1)
add(x);
else if(cmd == 2)
remove(x);
else{ // if cmd == 3;
if(find(x))
fout << 1 << "\n";
else
fout << 0 << "\n";
}
}
return 0;
}