Pagini recente » Cod sursa (job #1499313) | Cod sursa (job #2140224) | Cod sursa (job #1430780) | Cod sursa (job #1704183) | Cod sursa (job #2624632)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("hashuri.in");
ofstream fout("hashuri.out");
const int prim = 666013;
int n;
vector<int> hashh[prim];
bool caut(int x) {
int lista = x % prim;
for(auto &i : hashh[lista])
if(i == x)
return true;
return false;
}
bool inserez(int x) {
int lista = x % prim;
hashh[lista].push_back(x);
}
bool sterg(int x) {
int lista = x % prim;
for(auto &it:hashh[lista]) {
if (it == x) {
it = hashh[lista][hashh[lista].size() - 1];
hashh[lista].pop_back();
}
}
}
int main() {
int n, instr, x;
fin >> n;
for(int i = 0; i < n; ++i) {
fin >> instr >> x;
if(instr == 1)
inserez(x);
else if(instr == 2)
sterg(x);
else
fout << caut(x) << "\n";
}
return 0;
}