Pagini recente » Diferente pentru problema/portale intre reviziile 100 si 74 | Istoria paginii utilizator/dlaszlo2003 | Diferente pentru utilizator/luciant intre reviziile 7 si 6 | Cod sursa (job #1307081) | Cod sursa (job #2893730)
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
int n, p = 800077, i, x, operatie, hashedX, ok, j, vSize;
vector<vector<int>> hashMatrix(800077); //avem cate o lista pentru fiecare rest de la 0 la p - 1
int main()
{
in>>n;
for(i = 0; i < n; i++)
{
in>>operatie>>x;
hashedX = x % p;
vSize = hashMatrix[hashedX].size();
if(operatie == 1)
{
ok = 0;
for(j = 0; j < vSize; j++)
if(hashMatrix[hashedX][j] == x)
{
ok = 1;
break;
}
if(!ok)
hashMatrix[hashedX].push_back(x);
}
else if(operatie == 2)
{
for(j = 0; j < vSize; j++)
if(hashMatrix[hashedX][j] == x)
{
hashMatrix[hashedX][j] = hashMatrix[hashedX][vSize - 1];
hashMatrix[hashedX].pop_back();
break;
}
}
else
{
ok = 0;
for(j = 0; j < vSize; j++)
if(hashMatrix[hashedX][j] == x)
{
ok = 1;
break;
}
out<<ok<<'\n';
}
}
return 0;
}