Cod sursa(job #2617543)

Utilizator popoviciAna16Popovici Ana popoviciAna16 Data 21 mai 2020 22:21:00
Problema Curcubeu Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.91 kb
#include <fstream>
#include <cstring>
using namespace std;

ifstream fin("curcubeu.in");

class OutParser {

private:

    FILE *fout;

    char *buff;

    int sp;



    void write_ch(char ch) {

        if (sp == 50000) {

            fwrite(buff, 1, 50000, fout);

            sp = 0;

            buff[sp++] = ch;

        } else {

            buff[sp++] = ch;

        }

    }





public:

    OutParser(const char* name) {

        fout = fopen(name, "w");

        buff = new char[50000]();

        sp = 0;

    }

    ~OutParser() {

        fwrite(buff, 1, sp, fout);

        fclose(fout);

    }



    OutParser& operator << (int vu32) {

        if (vu32 <= 9) {

            write_ch(vu32 + '0');

        } else {

            (*this) << (vu32 / 10);

            write_ch(vu32 % 10 + '0');

        }

        return *this;

    }



    OutParser& operator << (long long vu64) {

        if (vu64 <= 9) {

            write_ch(vu64 + '0');

        } else {

            (*this) << (vu64 / 10);

            write_ch(vu64 % 10 + '0');

        }

        return *this;

    }



    OutParser& operator << (char ch) {

        write_ch(ch);

        return *this;

    }

    OutParser& operator << (const char *ch) {

        while (*ch) {

            write_ch(*ch);

            ++ch;

        }

        return *this;

    }

};

OutParser fout("curcubeu.out");

int n;
int a[4000001], lazy[4000001];

int qst, qdr, val;

void update(int nod, int st, int dr)
{
    if (lazy[nod] != 0 && st != dr)
    {
        a[nod<<1] = a[nod<<1|1] = lazy[nod<<1] = lazy[nod<<1|1] = lazy[nod];
        lazy[nod] = 0;
    }
    if (qst <= st && dr <= qdr)
    {
        a[nod] = val;
        lazy[nod] = val;
    }
    else
    {
        int mij = (st+dr)>>1;
        if (qst <= mij)
            update(nod<<1, st, mij);
        if (mij < qdr)
            update(nod<<1|1, mij+1, dr);
    }
}

int query(int poz)
{
    int st = 1, dr = n-1, mij, nod = 1;
    while (st < dr)
    {
        mij = (st+dr)>>1;
        if (lazy[nod] != 0)
        {
            a[nod<<1] = a[nod<<1|1] = lazy[nod<<1] = lazy[nod<<1|1] = lazy[nod];
            lazy[nod] = 0;
        }
        if (poz <= mij)
        {
            nod = nod << 1;
            dr = mij;
        }
        else
        {
            nod = nod<<1|1;
            st = mij+1;
        }
    }
    return a[nod];
}

int main()
{
    int a, b, i;
    fin >> n >> a >> b >> val;
    qst = min(a, b);
    qdr = max(a, b);
    update(1, 1, n-1);
    for (i = 2; i<n; i++)
    {
        a = (1ll*a*i)%n;
        b = (1ll*b*i)%n;
        val = (1ll*val*i)%n;
        qst = min(a, b);
        qdr = max(a, b);
        update(1, 1, n-1);
    }
    for (i = 1; i<n; i++)
        fout << query(i) << '\n';
    return 0;
}