Cod sursa(job #2632916)

Utilizator popoviciAna16Popovici Ana popoviciAna16 Data 5 iulie 2020 15:34:40
Problema Curcubeu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.06 kb
#include <cstdio>
#include <cstring>
 
using namespace std;
 
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;
    }
};

#include <fstream>
using namespace std;
 
ifstream fin("curcubeu.in");
OutParser fout("curcubeu.out");

int u[1000001];

int find(int x)
{
    int r = x, y;
    while (r < u[r])
        r = u[r];
    while (x != r)
    {
        y = u[x];
        u[x] = r;
        x = y;
    }
    return r;
}

struct {int l, r, c;} q[1000000];
int v[1000000];
 
int main()
{
    int n, i, a, b, c, j;
    fin >> n >> a >> b >> c;
    for (i = 1; i<n; i++)
    {
        a = (1ll*a*i)%n;
        b = (1ll*b*i)%n;
        c = (1ll*c*i)%n;
        q[i] = {min(a, b), max(a, b), c};
        u[i] = i;
    }
    u[n] = n;
    for (i = n-1; i>=1; i--)
        for (j = find(q[i].l); j <= q[i].r; j = find(j))
        {
            v[j] = q[i].c;
            u[j] = j+1;
        }
    for (i = 1; i<n; i++)
        fout << v[i] << '\n';
    return 0;
}