Pagini recente » Cod sursa (job #2699602) | Cod sursa (job #1312921) | Cod sursa (job #745999) | Cod sursa (job #1196847) | Cod sursa (job #3277799)
#include <fstream>
#include <vector>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout ("hashuri.out");
const int mod=665993;
const int base=11;
long long powers[15];
void powermaker()
{
int check=1;
powers[0] = 1;
for(int i=1;i<=14;i++)
{
powers[i]=check;
check*=base;
check%=mod;
}
}
vector <int> v[mod+5];
int hasher(int x)
{
long long newx=0;
int p=1;
while(x)
{
newx+=powers[p]*(x%10);
newx%=mod;
p++;
x/=10;
}
return newx;
}
bool finder(int val,int hashed)
{
bool flag=false;
for(int i=0;i<v[hashed].size();i++)
if(v[hashed][i]==val)
flag=true;
return flag;
}
int main()
{
int n;
cin>>n;
for(int k=1;k<=n;k++)
{
int c;
cin>>c;
int val,hashed;
cin>>val;
hashed=hasher(val);
if(c==1)
if(finder(val,hashed)==false)
v[hashed].push_back(val);
if(c==2)
{
for(int i=0;i<v[hashed].size();i++)
if(v[hashed][i]==val){
{
int last_idx = v[hashed].size() - 1;
swap(v[hashed][i],v[hashed][last_idx]);
v[hashed].pop_back();
break;
}
}
}
if(c==3)
{
if(finder(val,hashed))
cout<<"1\n";
else
cout<<"0\n";
}
}
return 0;
}