Pentru această operație este nevoie să te autentifici.

Cod sursă (job #396403)

Utilizator avatar contdeprostea2 SUBSCRIBETOPEWDIEPIE contdeprostea2 IP ascuns
Problemă Beculețe (clasele 9-10) Compilator cpp | 1,13 kb
Rundă Arhiva de probleme Status evaluat
Dată 23 oct. 2018 19:21:39 Scor 100
#include <stdio.h>
#define NMAX 50000

unsigned b[NMAX / 32  + 1];

void setup(int pos, int val) {
    unsigned mask = ~(1 << (pos & 31));
    b[pos >> 5] = (b[pos >> 5] & mask) ^ (val << (pos & 31));
}

int get(int pos) {
    return (b[pos >> 5] >> (pos & 31)) & 1;
}

void Xor(int n) {
    for (int w=n/32; w>=1; --w) {
        b[w] ^= b[w] << 1;
        b[w] ^= b[w - 1] >> 31;
    }
    b[0] ^= b[0] << 1;
}

int main() {
    int n, nd, defL, defC, defVal;
    FILE *f = fopen("beculete.in", "r");
    fscanf(f, "%d%d", &n, &nd);
    defL = 0;
    setup(0, 1);
    for (int i=1;i<n;++i) {
        int cp = get(i - 1);
        Xor(i);
        setup(i, cp);
        while (defL <= i) {
            if (defL == i)
                setup(defC, defVal);
            if (nd) {
                --nd;
                fscanf(f, "%d%d%d", &defL, &defC, &defVal);
                --defL;
                --defC;
            } else
                defL = n;
        }
    }
    fclose(f);
    f = fopen("beculete.out", "w");
    for (int i=0;i<n;++i)
        fprintf(f, "%d ", get(i));
    fclose(f);
    return 0;
}