Pagini recente » Cod sursa (job #654533) | Cod sursa (job #1530438) | Cod sursa (job #1063149) | Cod sursa (job #2143014) | Cod sursa (job #1513993)
#include <fstream>
using namespace std;
ifstream cin("hashuri.in");
ofstream cout("hashuri.out");
const int mod = 3000017;
int v[mod], n, tip, x;
int main () {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> tip >> x;
if (tip == 1) {
int pos = -1;
int p = x % mod;
for (int j = 0; ; ++j) {
if (j) {
p += 2 * (j - 1) + 1;
}
if (p >= mod) {
p -= mod;
}
if (v[p] == -1) {
pos = p;
}
if (v[p] == 0) {
if (pos != -1) {
v[pos] = x;
} else {
v[p] = x;
}
break;
} else if (v[p] == x) {
break;
}
}
} else if (tip == 2) {
int found = -1;
int p = x % mod;
for (int j = 0; ; ++j) {
if (j) {
p += 2 * (j - 1) + 1;
}
if (p >= mod) {
p -= mod;
}
if (v[p] == x) {
v[p] = -1;
break;
} else if (v[p] == 0) {
break;
}
}
} else if (tip == 3) {
int found = 0;
int p = x % mod;
for (int j = 0; ; ++j) {
if (j) {
p += 2 * (j - 1) + 1;
}
if (p >= mod) {
p -= mod;
}
if (v[p] == x) {
found = 1;
break;
} else if (v[p] == 0) {
break;
}
}
cout << found << "\n";
}
}
}