Cod sursa(job #1968627)

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

using namespace std;

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

int n;
int h[mod];
bitset < mod > st;

int nxt(int x) {
    srand(time(0));
    return (x + rand() % 10 + 1) & mod;
}

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

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

int _find(int x) {
    int pos = ((x & mod) * 17) & 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", (st[_find(x)] == 1));
    }

    return 0;
}