Cod sursa(job #2025186)

Utilizator mlc_oficialBoris Barca mlc_oficial Data 22 septembrie 2017 00:06:52
Problema Hashuri Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <cstdio>
#include <algorithm>
using namespace std;

const int mod0 = 662059, mod1 = 885421, mod2 = 592973, mod3 = 980731;

int s0[mod0], s1[mod1], s2[mod2], s3[mod3];

bool exists(int x) {
    return min({s0[x%mod0], s1[x%mod1], s2[x%mod2], s3[x%mod3]}) > 0;    
}

int main() {
    freopen("hashuri.in", "r", stdin);
    freopen("hashuri.out", "w", stdout);
    int q; 
    scanf("%d", &q);
    while (q--) {
        int op, x;
        scanf("%d%d", &op, &x);
        if (op == 3) printf("%d\n", exists(x));
        else if (op == 1) {
            if (exists(x)) continue;
            s0[x%mod0]++; s1[x%mod1]++; s2[x%mod2]++; s3[x%mod3]++;
        } else {
            if (!exists(x)) continue;
            s0[x%mod0]--; s1[x%mod1]--; s2[x%mod2]--; s3[x%mod3]--;
        }
    }
}