Pagini recente » Cod sursa (job #2472122) | Cod sursa (job #93100) | Cod sursa (job #2338886) | Cod sursa (job #886417) | Cod sursa (job #2233051)
#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,prime=2013013;
unsigned container[SIZE],pointer=0;
bitset <SIZE> flagged;
void inc(){
if (++pointer==SIZE)
pointer=0;
}
void hashfct(unsigned &key,unsigned target){
unsigned mask=0b11111111000000000000000000000000,aux=target&mask;
target>>=8;
target+=aux;
key=(1LL*target*prime)%SIZE;
aux=key&mask;
key>>=8;
key+=aux;
}
}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);
}
}