Cod sursa(job #2708137)

Utilizator CiboAndreiAndrei Cibo CiboAndrei Data 18 februarie 2021 12:50:57
Problema Curcubeu Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <bits/stdc++.h>

using namespace std;

//#define f cin
//#define g cout
//ifstream f("data.in");
//ofstream g("data.out");
ifstream f("curcubeu.in");
ofstream g("curcubeu.out");

const int dim = 1e6 + 2;
const short int mod = 1e9 + 7;

long long n, a, b, c;
int sol[dim];

struct str{
    long long x, y, z;
};
vector <str> v;

int inv[dim];

void init(){
    f >> n >> a >> b >> c;
}

void print_sol(){
    for(int i = 1; i < n; ++i)
        g << sol[i] << '\n';
}

void solve(){
    int i, j;

    for(i = 1; i < n; ++i){
        a = (a*i) % n;
        b = (b*i) % n;
        c = (c*i) % n;

        if(a < b){
            v.push_back({a, b, c});
        } else {
            v.push_back({b, a, c});
        }
    }

    for(i = n - 2; i >= 0; --i){
        a = v[i].x; b = v[i].y; c = v[i].z;

        for(j = a; j <= b; ++j){
            if(inv[j] == 0){
                sol[j] = c;
                inv[j] = b;
            } else j = inv[j];
        }
    }
}

int main(){
    init();
    solve();
    print_sol();

    return 0;
}