Pagini recente » Cod sursa (job #2267247) | ONIS 2015, Solutii Runda 1 | Cod sursa (job #1172564) | Profil | Cod sursa (job #1703464)
#include <iostream>
#include <fstream>
#define max_hash 2000000
#define max_n 1000000
using namespace std;
int start[max_hash];
int last[max_hash];
int next[1+max_n];
int val[1+max_n];
int hash_ (int x){
return x%max_hash;
}
void add_ ( int x, int poz ){
int p, i;
p = hash_(x);
i = start[p];
while ( i != 0 && val[i] != x){
i = next[i];
}
if(i==0 && start[p] ==0)
start[p] = last[p] = poz;
else{
if( i==0 ){
last[p] = next[last[p]] = poz;
}
}
}
void del ( int x ){
int p, i;
p = hash_(x);
if ( val[start[p]] == x){
start[p] = next[start[p]];
}else{
i = start[p];
while( next[i] !=0 && val[next[i]] !=x){
i = next[i];
}
if ( next[i] !=0 ){
next[i] = next[next[i]];
}
}
}
int query ( int x ){
int i, p;
p = hash_(x);
i = start[p];
while ( i!=0 && val[i]!=x){
i = next[i];
}
return i!=0;
}
int main()
{
ifstream f("hashuri.in");
ofstream g("hashuri.out");
int n, op, i;
f >> n;
for ( int i = 1; i<=n; i++ ){
f >> op >> val[i];
if ( op == 1 ){
add_(val[i], i);
}else{
if( op == 2 ){
del(val[i]);
}else{
g << query(val[i])<<"\n";
}
}
}
return 0;
}