Cod sursa(job #2025188)

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

const int mod0 = 662059, mod1 = 885421, mod2 = 592973, mod3 = 980731, mod4 = 351157, mod5 = 661513, mod6 = 611603, mod7 = 620821;

int s0[mod0], s1[mod1], s2[mod2], s3[mod3], s4[mod4], s5[mod5], s6[mod6], s7[mod7];

bool exists(int x) {
    return min({s0[x%mod0], s1[x%mod1], s2[x%mod2], s3[x%mod3], s4[x%mod4], s5[x%mod5], s6[x%mod6], s7[x%mod7]}) > 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]++;
            s4[x%mod4]++; s5[x%mod5]++; s6[x%mod6]++; s7[x%mod7]++;
        } else {
            if (!exists(x)) continue;
            s0[x%mod0]--; s1[x%mod1]--; s2[x%mod2]--; s3[x%mod3]--;
            s4[x%mod4]--; s5[x%mod5]--; s6[x%mod6]--; s7[x%mod7]--;
        }
    }
}