Cod sursa(job #2651399)

Utilizator OvidRata Ovidiu Ovid Data 22 septembrie 2020 16:14:06
Problema Curcubeu Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.24 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){

int lt=0;
for(int i=l; i<=r; ){
    if(res[i]==0){lt=i;res[i]=col;}
    forest.pb(i);
    i=ptr[i];
}
for(int j=0; (j<(forest.size())) && (forest[j]<lt); j++ ){
    ptr[forest[j] ]=lt;
} forest.clear();
//cout<<lt<<" "<<flush;
return;
}





int32_t main(){
INIT
cin>>n>>a[1]>>b[1]>>c[1];
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;
}
for(int i=1; i<=(n); i++){
    ptr[i]=i+1;
}
for(int i=(n-1); i>=1; i--){
    colour(min(a[i], b[i]), max(a[i], b[i]), c[i] );
}
for(int i=1; i<n; i++){
    cout<<res[i]<<"\n";
}

return 0;
}