Cod sursa(job #1785012)

Utilizator AlexNiuclaeNiculae Alexandru Vlad AlexNiuclae Data 20 octombrie 2016 19:53:27
Problema Hashuri Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <bits/stdc++.h>

using namespace std;

const int mod = 480000000;
const int rand_n = 970005041;

int n, type, x;
bitset < mod + 10 > hash_;

int find_pos(int x)
{
    x ^= rand_n;
    x *= x;
    x %= mod;
    return x;
}

void update(int x, int v)
{
    int pos = find_pos(x);
    hash_[pos] = v;
}

int check(int x)
{
    int pos = find_pos(x);
    return hash_[pos];
}

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

    for (scanf("%d", &n); n ; --n)
    {
        scanf("%d %d", &type, &x);

        if (type <= 2)
            update(x, type & 1);
        if (type == 3)
            printf("%d\n", check(x));
    }

    return 0;
}