Pagini recente » Cod sursa (job #2533312) | Cod sursa (job #1521332) | Cod sursa (job #1039529) | Cod sursa (job #1853050) | Cod sursa (job #2233053)
#include <bits/stdc++.h>
using namespace std;
ifstream f ("hashuri.in");
ofstream t ("hashuri.out");
int n;
class hash{
public:
hash (){};//C-TOR
void add(unsigned target){
hashfct(pointer,target);
FLAG1:
if (container[pointer]==target){
flagged[pointer]=false;
return;
}
else if (container[pointer]==0)
container[pointer]=target;
else{
inc();
goto FLAG1;
}
}
void remov(unsigned target){
hashfct(pointer,target);
FLAG2:
if (container[pointer]==target){
flagged[pointer]=true;
return;
}
else if (container[pointer]==0)
return;
else{
inc();
goto FLAG2;
}
}
bool check(unsigned target){
hashfct(pointer,target);
FLAG3:
if (container[pointer]==target and !flagged[pointer])
return true;
else if ((container[pointer]==target and flagged[pointer]) or container[pointer]==0) return false;
else{
inc();
goto FLAG3;
}
}
~hash (){
memset(container,0,sizeof(container));
}//D-TOR
private:
static const int SIZE=10000010,PRIM1=21313,PRIM2=19937;
unsigned container[SIZE],pointer=0;
bitset <SIZE> flagged;
void inc(){
if (++pointer==SIZE)
pointer=0;
}
void hashfct(unsigned &key,unsigned target){
key=target%SIZE;
unsigned mask=0xF0000000;
key=(1LL*key*PRIM1)%SIZE;
key=(1LL*key*PRIM2)%SIZE;
target|=mask;
target>>=28;
key<<=4;
key+=target;
key%=SIZE;
}
}h;
void handle(int type,int target){
if (type==1) h.add(target);
else if (type==2) h.remov(target);
else t<<h.check(target)<<'\n';
}
int main(){
f>>n;
for (int op,target;n;--n){
f>>op>>target;
handle(op,target);
}
}