Cod sursa(job #3181135)

Utilizator Robert_MitriRobert Mitri Robert_Mitri Data 6 decembrie 2023 15:39:13
Problema Curcubeu Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>
#define sz 1000000
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");


int n,a,b,c;

struct query{
int a;
int b;
int c;
}q[sz + 5];

int nxt[sz + 5];

int get_nxt(int poz)
{
    int cp = poz;
    while(nxt[poz] != poz)
        poz=nxt[poz];
    while(cp != poz){
        int aux = nxt[cp];
        nxt[cp]=poz;
        cp=aux;
    }
    return cp;
}
int v[sz + 5];

int main()
{
    fin>>n>>q[1].a>>q[1].b>>q[1].c;
    if(q[1].a > q[1].b)
        swap(q[1].a,q[1].b);
    for(int i=1;i<=n;i++)
        nxt[i]=i;
    for(int i=2;i<n;i++)
    {
        q[i].a = (1LL*q[i-1].a * i) % n;
        q[i].b = (1LL*q[i-1].b * i) % n;
        if(q[i].a>q[i].b)
            swap(q[i].a,q[i].b);
        q[i].c = (1LL*q[i-1].c * i) % n;
    }
    for(int i = n-1; i > 0;i--)
        for(int j = get_nxt(q[i].a);j<=q[i].b;j=nxt[j]){
            v[j]=q[i].c;
            nxt[j]=get_nxt(j+1);
        }
    for(int i=1;i<n;i++)
        fout<<v[i]<<'\n';

}