Pagini recente » Cod sursa (job #1060713) | Cod sursa (job #2799144) | Cod sursa (job #719770) | Cod sursa (job #746780) | Cod sursa (job #732220)
Cod sursa(job #732220)
#include <stdio.h>
#include <fstream>
#include <vector>
#define val 666013
using namespace std;
int n;
vector <int> mul[val];
inline vector<int>::iterator cautare(int x){
vector <int>::iterator it;
int pos = x % val;
for(it = mul[pos].begin(); it != mul[pos].end(); ++it)
if(*it == x)
return it;
return mul[pos].end();
}
inline void inserare(int x){
int pos = x % val;
if(cautare(x) == mul[pos].end())
mul[pos].push_back(x);
}
inline void stergere(int x){
int pos = x % val;
vector<int>::iterator it = cautare(x);
if (it != mul[pos].end())
mul[pos].erase(it);
}
int main(){
int operatie, x;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
f >> n;
for(n; n; --n){
f >> operatie >> x;
if(operatie == 1){
inserare(x);
continue;
}
if(operatie == 2){
stergere(x);
continue;
}
g << (cautare(x) != mul[x % val].end());
}
f.close();
g.close();
return 0;
}