Pagini recente » Cod sursa (job #1441875) | Cod sursa (job #954661) | Cod sursa (job #2548413) | Cod sursa (job #1610970) | Cod sursa (job #3152203)
#include <iostream>
#include <fstream>
#include <list>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
const int maxn = 1e6;
struct colorare {
int a;
int b;
int c;
colorare() = default;
colorare(int a, int b, int c) {
this->a = min(a, b);
this->b = max(a, b);
this->c = c;
}
};
colorare rng[maxn];
int answer[maxn];
int flw[maxn];
bool occ[maxn];
int getflw(int poz) {
if (poz == -1)
return -1;
cout << poz << endl;
int val = flw[poz];
cout << val << endl;
while (val != -1 && occ[val])
val = flw[val], cout << val << endl;
return flw[poz] = val;
}
int main() {
int n, a, b, c;
fin >> n >> a >> b >> c;
int cnt = 1;
do {
rng[cnt] = colorare(a, b, c);
cnt++;
a = (1LL*a*cnt)%n;
b = (1LL*b*cnt)%n;
c = (1LL*c*cnt)%n;
} while (cnt < n);
// for (int i = 1; i < n - 1; i++)
// flw[i] = i + 1;
// flw[n - 1] = -1;
for (int i = n - 1; i > 0; i--) {
//cout << ranges[i].a << ' ' << ranges[i].b << ' ' << ranges[i].c << '\n';
for (int j = rng[i].a; j <= rng[i].b; j++) {
if (flw[j] == 0) {
answer[j] = rng[i].c;
flw[j] = rng[i].b;
} else {
j = flw[j];
}
}
// while (poz != -1 && occ[poz])
// poz = getflw(poz);
// while (poz != -1 && poz <= ranges[i].b) {
// occ[poz] = true;
// answer[poz] = ranges[i].c;
// poz = getflw(poz);
// }
}
for (int i = 1; i < n; i++)
fout << answer[i] << '\n';
return 0;
}