Pagini recente » Cod sursa (job #978245) | Cod sursa (job #2520301) | Cod sursa (job #1466261) | Cod sursa (job #2472407) | Cod sursa (job #2876061)
#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");
class OutParser {
private:
FILE *fout;
char *buff;
int sp;
void write_ch(char ch) {
if (sp == 50000) {
fwrite(buff, 1, 50000, fout);
sp = 0;
buff[sp++] = ch;
} else {
buff[sp++] = ch;
}
}
public:
OutParser(const char* name) {
fout = fopen(name, "w");
buff = new char[50000]();
sp = 0;
}
~OutParser() {
fwrite(buff, 1, sp, fout);
fclose(fout);
}
OutParser& operator << (int vu32) {
if (vu32 <= 9) {
write_ch(vu32 + '0');
} else {
(*this) << (vu32 / 10);
write_ch(vu32 % 10 + '0');
}
return *this;
}
OutParser& operator << (long long vu64) {
if (vu64 <= 9) {
write_ch(vu64 + '0');
} else {
(*this) << (vu64 / 10);
write_ch(vu64 % 10 + '0');
}
return *this;
}
OutParser& operator << (char ch) {
write_ch(ch);
return *this;
}
OutParser& operator << (const char *ch) {
while (*ch) {
write_ch(*ch);
++ch;
}
return *this;
}
};
OutParser fout("curcubeu.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;
}