Cod sursa(job #1968605)

Utilizator AlexNiuclaeNiculae Alexandru Vlad AlexNiuclae Data 17 aprilie 2017 19:26:15
Problema Hashuri Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <bits/stdc++.h>

using namespace std;

const int mod = (1 << 22) - 1;

int n;
int h[mod];

int nxt(int x) {
    return ((x << 2) ^ (x << 1) ^ (x << 3)) & mod;
}

void _add(int x, int pos) {
    h[pos] = x;
}

void _delete(int x, int pos) {
    h[pos] = 0;
}

int _find(int x) {
    int pos = x & mod;
    for ( ; h[pos] && h[pos] != x; pos = nxt(pos));
    return pos;
}

int main() {
    freopen("hashuri.in","r",stdin);
    freopen("hashuri.out","w",stdout);

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        int type, x; scanf("%d %d", &type, &x);
        if (type == 1)
            _add(x, _find(x));
        if (type == 2)
            _delete(x, _find(x));
        if (type == 3)
            printf("%d\n", (h[_find(x)] == x));
    }

    return 0;
}