Cod sursa(job #1808679)

Utilizator moise_alexandruMoise Alexandru moise_alexandru Data 17 noiembrie 2016 23:11:09
Problema Curcubeu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.54 kb
#include <algorithm>
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("curcubeu.in");
const int maxn = 1000005;
int ind[maxn];
int v[maxn];
struct upd
{
    int a, b, c;
};
upd u[maxn];

inline upd make_update(int A, int B, int C)
{
    upd aux;
    aux.a = A;
    aux.b = B;
    aux.c = C;
    return aux;
}

void update(upd x)
{
    int A = x.a;
    int B = x.b;
    if(A > B)
        swap(A, B);
    int C = x.c;
    int p = A;
    while(p <= B)
    {
        if(v[p] == 0)
        {
            v[p] = C;
            ind[p] = B + 1;
            p++;
        }
        else
            p = ind[p];
    }
}

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;
    }
};

int main()
{
    int n, A, B, C;
    in >> n >> A >> B >> C;
    u[1] = make_update(A, B, C);
    OutParser fout("curcubeu.out");
    for(int i = 2; i < n; i++)
    {
        A = (1LL * A * i) % n;
        B = (1LL * B * i) % n;
        C = (1LL * C * i) % n;
        u[i] = make_update(A, B, C);
    }
    for(int i = 1; i <= n; i++)
        ind[i] = i + 1;
    reverse(u + 1, u + n);
    for(int i = 1; i < n; i++)
        update(u[i]);
    for(int i = 1; i <= n - 1; i++)
        fout << v[i] << "\n";
    return 0;
}