Pagini recente » Cod sursa (job #2406539) | Cod sursa (job #1322534) | Cod sursa (job #2421006) | Cod sursa (job #2986238) | Cod sursa (job #2872175)
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("hashuri.in");
ofstream out("hashuri.out");
const int mx=3e6;
const long long p1=872742023,p2=489174503;
const long long a=324892358,b=728741242;
const long long c=817247897,d=682739174;
int t1[mx],t2[mx];
long long h1(long long x){
return ((a*x+b)%p1)%mx;
}
long long h2(long long x){
return ((c*x+d)%p2)%mx;
}
bool find(int x){
return t1[h1(x)]==x || t2[h2(x)]==x;
}
void remove(int x){
int hash1=h1(x),hash2=h2(x);
if(t1[hash1]==x){
t1[hash1]=0;
}
else if(t2[hash2]==x){
t2[hash2]=0;
}
}
void insert(int x){
if(find(x))
return;
int hash1=h1(x),hash2=h2(x);
while(true){
if(t1[hash1]==0){
t1[hash1]=x;
return;
}
swap(x,t1[hash1]);
hash1=h1(x);
hash2=h2(x);
if(t2[hash2]==0){
t2[hash2]=x;
return;
}
swap(x,t2[hash2]);
hash1=h1(x);
hash2=h2(x);
}
}
void solve(){
int n,op,x;
in>>n;
for(int i=0;i<n;i++){
in>>op>>x;
if(op==1){
insert(x);
}
else if(op==2){
remove(x);
}
else{
out<<find(x)<<'\n';
}
}
}
int main(){
solve();
return 0;
}