Cod sursa(job #2651410)

Utilizator OvidRata Ovidiu Ovid Data 22 septembrie 2020 16:28:23
Problema Curcubeu Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

ifstream fin("curcubeu.in"); ofstream fout("curcubeu.out");
#define cin fin
#define cout fout



int t, n;
int a[1000010];
int b[1000010];
int c[1000010];
int ptr[1000010];
int res[1000010];
vector<int> forest;
void colour(int l, int r, int col){

//cout<<lt<<" "<<flush;
return;
}





int32_t main(){
INIT
cin>>n>>a[1]>>b[1]>>c[1];
ptr[1]=2;
for(int i=2; i<=(n-1); i++){
    a[i]=(a[i-1]*i)%n;
    b[i]=(b[i-1]*i)%n;
    c[i]=(c[i-1]*i)%n;ptr[i]=(i+1);
}

for(int i=(n-1); i>=1; i--){
    int lt=0;
for(int j=min(a[i], b[i]); j<=max(a[i], b[i]); ){
    lt=ptr[j];if(res[j]==0){res[j]=c[i];}
    forest.pb(j);
    j=ptr[j];
}int t;
for(int j=min(a[i], b[i]); j<=max(a[i], b[i]); ){
    t=ptr[j];
    ptr[j]=lt;
    j=t;
}


}
for(int i=1; i<n; i++){
    cout<<res[i]<<"\n";
}

return 0;
}