Pagini recente » Cod sursa (job #1078965) | Cod sursa (job #31470) | Cod sursa (job #2918215) | Cod sursa (job #2404538) | Cod sursa (job #2876054)
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x <<": " << x << "\n";
using ll = long long;
const string fn = "curcubeu";
ifstream fin(fn + ".in");
ofstream fout(fn + ".out");
const int x = 5;
int a[1000005], b[1000005], c[1000005];
int nxt[1000005], color[1000005];
int n;
int findd(int x) {
int r = x, y;
while (r < n && color[nxt[r]] != 0)
r = nxt[r];
r = nxt[r];
while (x < n && color[nxt[x]]) {
y = nxt[x];
nxt[x] = r;
x = y;
}
return r;
}
int main() {
fin >> n >> a[1] >> b[1] >> c[1];
if (a[1] > b[1]) swap(a[1], b[1]);
for (int i = 2; i <= n - 1; ++i) {
a[i] = (1LL * a[i - 1] * i) % n;
b[i] = (1LL * b[i - 1] * i) % n;
c[i] = (1LL * c[i - 1] * i) % n;
if (a[i] > b[i]) swap(a[i], b[i]);
}
for (int i = 1; i < n; ++i)
nxt[i] = i + 1;
color[n] = 0;
for (int p = n - 1; p >= 1; --p) {
int A = a[p];
int B = b[p];
int C = c[p];
int i = A;
while (color[i] && i <= B) i = findd(i);
for (; i <= B; i = findd(i))
color[i] = C;
}
for (int i = 1; i < n; ++i)
fout << color[i] << "\n";
return 0;
}