-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_table.cpp
More file actions
69 lines (65 loc) · 1.07 KB
/
hash_table.cpp
File metadata and controls
69 lines (65 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/// https://infoarena.ro/problema/hashuri
#include<cstdio>
#include<fstream>
#include<vector>
using namespace std;
FILE *f=fopen("hashuri.in","r");
ofstream g("hashuri.out");
#define MOD 666013
vector<int> v[666015];
void adauga(int x)
{
int y,i,n,ok=0;
y=x%MOD;
n=v[y].size();
for(i=0;i<n;i++)
if(v[y][i]==x)
{
ok=1;
break;
}
if(ok==0)
v[y].push_back(x);
}
void sterge(int x)
{
int y,i,n;
y=x%MOD;
n=v[y].size();
for(i=0;i<n;i++)
if(v[y][i]==x)
{
v[y].erase(v[y].begin()+i);
break;
}
}
void cauta(int x)
{
int y,i,n,ok=0;
y=x%MOD;
n=v[y].size();
for(i=0;i<n;i++)
if(v[y][i]==x)
{
ok=1;
break;
}
g<<ok<<'\n';
}
int main()
{
int i,n,p,x;
fscanf(f,"%d",&n);
for(i=1;i<=n;i++)
{
fscanf(f,"%d%d",&p,&x);
if(p==1)
adauga(x);
else
if(p==2)
sterge(x);
else
cauta(x);
}
return 0;
}