Cod sursa(job #2351899)

Utilizator FunnyStockyMihnea Andreescu FunnyStocky Data 22 februarie 2019 19:52:10
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>

using namespace std;

ifstream cin("curcubeu.in");
ofstream cout("curcubeu.out");

const int Limit = 1000000 + 7;

int n;

int First[Limit];
int Last[Limit];
int Color[Limit];

int FinalColor[Limit];

int Next[Limit];

int main()
{
  cin >> n;
  cin >> First[1] >> Last[1] >> Color[1];
  for (int i = 2; i < n; i++)
  {
    First[i] = First[i - 1] * (long long) i % n;
    Last[i] = Last[i - 1] * (long long) i % n;
    Color[i] = Color[i - 1] * (long long) i % n;
  }
  for (int i = 0; i < Limit; i++)
  {
    Next[i] = i + 1;
  }
  for (int i = n - 1; i >= 0; i--)
  {
    if (First[i] > Last[i])
    {
      swap(First[i], Last[i]);
    }
    for (int j = First[i]; j <= Last[i]; j = Next[j])
    {
      if (FinalColor[j] == 0)
      {
        FinalColor[j] = Color[i];
        Next[j] = Last[i] + 1;
      }
    }
  }
  for (int i = 1; i < n; i++)
  {
    cout << FinalColor[i] << "\n";
  }
}