Pagini recente » Rating Emilian Paraicu (emilianparaicu14) | Cod sursa (job #3171607) | Cod sursa (job #2658602) | Cod sursa (job #585634) | Cod sursa (job #641704)
Cod sursa(job #641704)
#include <cstdlib>
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
vector <int> v[666013];
const int CONST=666013;
bool search(int x){
int poz=x%CONST;
vector <int> :: iterator it;
for (it=v[poz].begin();it!=v[poz].end();it++){
if (*it==x){
return 1;
break;
}
}
return 0;
}
void adauga(int x){
if (search(x)==0){
v[x%CONST].push_back(x);
}
}
void sterge(int x){
int poz=x%CONST;
vector <int> :: iterator it;
for (it=v[poz].begin();it!=v[poz].end();it++){
if (*it==x){
v[poz].erase(it);
break;
}
}
}
int main(int argc, char *argv[])
{
int i,n,x,op;
in>>n;
for (i=1;i<=n;i++){
in>>op;
in>>x;
if (op==1){
adauga(x);
}
else if (op==2)
{
sterge(x);
} else {
out<<search(x)<<"\n";
}
}
return 0;
}