Cod sursa(job #2154977)

Utilizator amaliarebAmalia Rebegea amaliareb Data 7 martie 2018 14:27:45
Problema Hashuri Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.01 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("hashuri.in");
ofstream g("hashuri.out");
const int mod = 666013, MaxN = 1000005;
int n, urm[MaxN], val[MaxN], start[mod], ind;

int Check(int x) {
    int poz = start[x % mod];
    while (poz && val[poz] != x) poz = urm[poz];
    return poz;
}

void Add(int x) {
    if (Check(x)) {
        //++fr[Check(x)];
        return;
    }
    val[++ind] = x;
    urm[ind] = start[x % mod];
    start[x % mod] = ind;
}

void Del(int x) {
    int poz = start[x % mod];
    if (val[poz] == x) {
        //--fr[poz];
        start[x % mod] = urm[poz];
        return;
    }
    while (urm[poz] && val[urm[poz]] != x) poz = urm[poz];
    //if (val[urm[poz]] == x) --fr[urm[poz]];
    urm[poz] = urm[urm[poz]];
}


int main()
{
    f >> n;
    for (int i = 1; i <= n; ++i) {
        int op, x;
        f >> op >> x;
        if (op == 1) Add(x);
        else if (op == 2) Del(x);
        else g << (Check(x) > 0) << '\n';
    }
    return 0;
}