1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| #include <bits/stdc++.h> using namespace std; typedef long long ll; #define per(i,a,n) for (int i=a;i<n;i++) #define rep(i,a,n) for (int i=n-1;i>=a;i--) const int MAXN(5e6+7); int N; ll X[MAXN], Y[MAXN], A1,B1,C1,M1,A2,B2,C2,M2; struct nd{ ll L, R; }ope[MAXN]; ll qp[2*MAXN]; ll lnm[2*MAXN]; int cntt=9; ll ans[MAXN << 2], lazy[MAXN << 2]; inline void PushUp(int rt) { ans[rt] = ans[rt << 1] + ans[rt << 1 | 1]; } inline void Build(int l, int r, int rt) { if (l == r) { ans[rt] = 0; return; } int mid = (l + r) >> 1; Build(l, mid, rt << 1); Build(mid + 1, r, rt << 1 | 1); PushUp(rt); } inline void PushDown(int rt, ll ln, ll rn) { if (lazy[rt]) { lazy[rt << 1] += lazy[rt]; lazy[rt << 1 | 1] += lazy[rt]; ans[rt << 1] += lazy[rt] * ln; ans[rt << 1 | 1] += lazy[rt] * rn; lazy[rt] = 0; } } inline void Update(int L, int R, int l, int r, int rt) { if (L <= l && r <= R) { ans[rt] += (qp[r+1] - qp[l]); lazy[rt] ++; return; } int mid = (l + r) >> 1; PushDown(rt, qp[mid+1] - qp[l], qp[r+1] - qp[mid+1]); if (L <= mid) { Update(L, R, l, mid, rt << 1); } if (R > mid) { Update(L, R, mid + 1, r, rt << 1 | 1); } PushUp(rt); } inline ll Query(ll C, int l, int r, int rt) { if(l==r) { C = (C-1)/(ans[rt]/(qp[l+1]-qp[l]))+1; return qp[l]+C-1; } int mid = (l + r) >> 1; PushDown(rt, qp[mid+1] - qp[l], qp[r+1] - qp[mid+1]); if (C <= ans[rt<<1]) { return Query(C, l, mid, rt << 1); } else { return Query(C-ans[rt<<1], mid + 1, r, rt << 1 | 1); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N; cin >> X[1] >> X[2] >> A1 >> B1 >> C1 >> M1 >> Y[1] >> Y[2] >> A2 >> B2 >> C2 >> M2; ope[1].L = min(X[1], Y[1])+1; ope[1].R = max(X[1], Y[1])+1; ope[2].L = min(X[2], Y[2])+1; ope[2].R = max(X[2], Y[2])+1; qp[1] = ope[1].L; qp[2] = ope[1].R; qp[3] = ope[2].L; qp[4] = ope[2].R; qp[5] = ope[1].L+1; qp[6] = ope[1].R+1; qp[7] = ope[2].L+1; qp[8] = ope[2].R+1; per(i, 3, N+1) { X[i] = (A1*X[i-1]%M1 + B1*X[i-2]%M1 + C1)%M1; Y[i] = (A2*Y[i-1]%M2 + B2*Y[i-2]%M2 + C2)%M2; ope[i].L = min(X[i], Y[i])+1; ope[i].R = max(X[i], Y[i])+1; qp[cntt++] = ope[i].L; qp[cntt++] = ope[i].L+1; qp[cntt++] = ope[i].R; qp[cntt++] = ope[i].R+1; } sort(qp+1, qp+cntt); cntt = unique(qp+1, qp+cntt)-qp; per(i, 1, cntt) { lnm[i] = qp[i+1]-qp[i]; } per(i, 1, N+1) { ope[i].L = lower_bound(qp, qp+cntt, ope[i].L)-qp; ope[i].R = lower_bound(qp, qp+cntt, ope[i].R)-qp; } cntt--; ll sumpt=0; Build(1, cntt, 1); per(i, 1, N+1) { sumpt += (qp[ope[i].R+1]-qp[ope[i].L]); Update(ope[i].L, ope[i].R, 1, cntt, 1); cout << Query((sumpt+1)/2, 1, cntt, 1) << endl; } return 0; }
|