Pagini recente » Cod sursa (job #155318) | Cod sursa (job #2108206) | Cod sursa (job #2047732) | Cod sursa (job #1648857) | Cod sursa (job #85318)
Cod sursa(job #85318)
#include <cstdio>
#include <vector>
using namespace std;
#define pb push_back
#define sz(c) int((c).size())
const int Nmax = 1000005;
int a[Nmax], b[Nmax], c[Nmax];
int v1[Nmax], v2[Nmax];
int A[Nmax], B[Nmax];
int n;
int heap[Nmax], loc[Nmax], dim;
inline void swap(int &a, int &b) { a ^= b ^= a ^= b; }
void ReadData() {
scanf("%d %d %d %d", &n, &a[1], &b[1], &c[1]);
for (int i = 2; i < n; ++i) {
long long aux;
aux = a[i-1];
aux *= static_cast<long long>(i);
aux %= static_cast<long long>(n);
a[i] = aux;
aux = b[i-1];
aux *= static_cast<long long>(i);
aux %= static_cast<long long>(n);
b[i] = aux;
aux = c[i-1];
aux *= static_cast<long long>(i);
aux %= static_cast<long long>(n);
c[i] = aux;
}
for (int i = 1; i < n; ++i)
if (a[i] > b[i]) swap(a[i], b[i]);
for (int i = 1; i < n; ++i)
++v1[a[i]];
for (int i = 1; i < n; ++i)
v1[i] += v1[i-1];
for (int i = n-1; i; --i)
A[ v1[a[i]]-- ] = i;
for (int i = 1; i < n; ++i)
++v2[b[i]];
for (int i = 1; i < n; ++i)
v2[i] += v2[i-1];
for (int i = n-1; i; --i)
B[ v2[b[i]]-- ] = i;
}
void reconst(int p) {
if (p == 1 || heap[p/2] > heap[p]) return;
swap(heap[p/2], heap[p]);
swap(loc[heap[p/2]], loc[heap[p]]);
reconst(p/2);
}
void insert(int nod) {
heap[++dim] = nod;
loc[nod] = dim;
reconst(dim);
}
void reconst2(int p) {
int k = p;
if (2*p <= dim && heap[2*p] > heap[k]) k = 2*p;
if (2*p+1 <= dim && heap[2*p+1] > heap[k]) k = 2*p+1;
if (k != p) {
swap(heap[p], heap[k]);
swap(loc[heap[p]], loc[heap[k]]);
reconst2(k);
}
}
void scoate(int nod) {
while (loc[nod] > 1) {
int p = loc[nod];
swap(heap[p/2], heap[p]);
swap(loc[heap[p/2]], loc[heap[p]]);
}
heap[1] = heap[dim--];
loc[heap[1]] = 1;
reconst2(1);
}
void Solve() {
int indA = 1, indB = 1;
for (int i = 1; i < n; ++i) {
while (indA < n && a[A[indA]] <= i) insert(A[indA++]);
while (indB < n && b[B[indB]]+1 <= i) scoate(B[indB++]);
if (dim == 0) printf("0\n");
else printf("%d\n", c[heap[1]]);
}
}
int main() {
freopen("curcubeu.in", "r", stdin);
freopen("curcubeu.out", "w", stdout);
ReadData();
Solve();
}