Cod sursă (job #525808)

Utilizator avatar stefan.popescu Popescu Stefan stefan.popescu IP ascuns
Problemă Beculețe (clasele 9-10) Compilator cpp | 1,00 kb
Rundă Arhiva de probleme Status evaluat
Dată 9 feb. 2020 15:55:37 Scor 10
#include <iostream>
#include <fstream>
using namespace std;
ifstream in ("beculete.in");
ofstream out("beculete.out");
const int NMAX=50010;
int a[NMAX/32+2];
int n, d, state, ll, cc;
void setbit(int poz, int val)
{
    int chunk=poz>>5;
    int buc=poz&((1<<5)-1);
    char mask=1<<buc;
    a[chunk]&=~mask;
    a[chunk]|=(val<<buc);
}
int getbit(int poz)
{
    int chunk=poz>>5;
    int buc=poz&((1<<5)-1);
    return (a[chunk]>>buc)&1;
}
int main()
{
    in>>n>>d;
    a[0]=1;
    if(d)
        in>>ll>>cc>>state;
    for(int i=2; i<=n; i++)
    {
        int temp1=0, temp2=0, j;
        for(j=0; (j<<5)<=i; j++)
        {
            temp1=a[j]>>31;
            int mask=(a[j]<<1)+temp2;
            a[j]^=mask;
            temp2=temp1&1;
        }
        a[j]=temp1;
        while(ll==i&&d)
        {
            d--;
            setbit(cc-1, state);
            in>>ll>>cc>>state;
        }
    }
    for(int i=0; i<n; i++)
        out<<getbit(i)<<" ";
    return 0;
}