Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// author: Mr.Hakimov
- #include <bits/stdc++.h>
- #define fi first
- #define se second
- #define pb push_back
- #define pf push_front
- #define Pb pop_back
- #define Pf pop_front
- #define all(x) (x).begin(), (x).end()
- #define fin(s) freopen(s, "r", stdin);
- #define fout(s) freopen(s, "w", stdout);
- /* Just some advices:
- 1. If I use set/multiset, I will check it - is it correct to use set/multiset in a problem?
- 2. If I can't solve problem, I must write a program, which could help me to understand it much more better)
- ...
- */
- using namespace std;
- typedef long long LL;
- typedef long double LD;
- int TN = 1;
- void solve() {
- int n;
- LL x, y, a0;
- cin >> n >> x >> y >> a0;
- LL ai1 = a0;
- vector < LL > sum(n);
- sum[0] = a0;
- for (int i = 1; i < n; i++) {
- LL ai = (x * ai1 + y + (1 << 16)) % (1 << 16);
- sum[i] = sum[i - 1] + ai;
- ai1 = ai;
- }
- int m;
- LL z, t, b0;
- cin >> m >> z >> t >> b0;
- vector < LL > c(2 * m);
- LL bi1 = b0;
- for (int i = 1; i < 2 * m; i++) {
- LL bi = (z * bi1 + t + (1 << 30)) % (1 << 30);
- c[i] = bi % n;
- bi1 = bi;
- }
- if (m > 0) {
- c[0] = b0 % n;
- }
- LL ans = 0;
- for (int i = 0; i < 2 * m; i += 2) {
- int x = min(c[i], c[i + 1]) - 1;
- if (x < 0) {
- ans += sum[min(1ll * n - 1, max(c[i], c[i + 1]))];
- } else {
- ans += sum[min(1ll * n - 1, max(c[i], c[i + 1]))] - sum[x];
- }
- }
- cout << ans;
- }
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(nullptr); cout.tie(nullptr);
- /// =========================================
- /// fin("input.txt"); fout("output.txt");
- /// fin("file.in"); fout("file.out");
- /// cin >> TN;
- /// =========================================
- while (TN--) solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement