Pagini recente » Cod sursa (job #2529641) | Cod sursa (job #2463620) | Cod sursa (job #2305110) | Cod sursa (job #1490162) | Cod sursa (job #2872474)
#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,p3=712468712;
const long long a=324892358,b=728741242;
const long long c=817247897,d=682739174;
const long long e=198273124,f=935478201;
int t1[mx],t2[mx],t3[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;
}
long long h3(long long x){
return ((e*x+f)%p3)%mx;
}
bool find(int x){
return t1[h1(x)]==x || t2[h2(x)]==x ||t3[h3(x)]==x;
}
void remove(int x){
int hash1=h1(x),hash2=h2(x),hash3=h3(x);
if(t1[hash1]==x){
t1[hash1]=0;
}
else if(t2[hash2]==x){
t2[hash2]=0;
}
else if(t3[hash3]==x){
t3[hash3]=0;
}
}
void insert(int x){
if(find(x))
return;
int hash1=h1(x),hash2=h2(x),hash3=h3(x);
while(true){
if(t1[hash1]==0){
t1[hash1]=x;
return;
}
swap(x,t1[hash1]);
hash1=h1(x);
hash2=h2(x);
hash3=h3(x);
if(t2[hash2]==0){
t2[hash2]=x;
return;
}
swap(x,t2[hash2]);
hash1=h1(x);
hash2=h2(x);
hash3=h3(x);
if(t3[hash3]==0){
t3[hash3]=x;
return;
}
swap(x,t3[hash3]);
hash1=h1(x);
hash2=h2(x);
hash3=h3(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;
}