Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.84 KB | None | 0 0
  1. /// author: Mr.Hakimov
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. #define fi first
  6. #define se second
  7. #define pb push_back
  8. #define pf push_front
  9. #define Pb pop_back
  10. #define Pf pop_front
  11. #define all(x) (x).begin(), (x).end()
  12. #define fin(s) freopen(s, "r", stdin);
  13. #define fout(s) freopen(s, "w", stdout);
  14.  
  15. /* Just some advices:
  16. 1. If I use set/multiset, I will check it - is it correct to use set/multiset in a problem?
  17. 2. If I can't solve problem, I must write a program, which could help me to understand it much more better)
  18. ...
  19. */
  20.  
  21. using namespace std;
  22.  
  23. typedef long long LL;
  24. typedef long double LD;
  25.  
  26. int TN = 1;
  27.  
  28. void solve() {
  29.     int n;
  30.     LL x, y, a0;
  31.     cin >> n >> x >> y >> a0;
  32.     LL ai1 = a0;
  33.     vector < LL > sum(n);
  34.     sum[0] = a0;
  35.     for (int i = 1; i < n; i++) {
  36.         LL ai = (x * ai1 + y + (1 << 16)) % (1 << 16);
  37.         sum[i] = sum[i - 1] + ai;
  38.         ai1 = ai;
  39.     }
  40.     int m;
  41.     LL z, t, b0;
  42.     cin >> m >> z >> t >> b0;
  43.     vector < LL > c(2 * m);
  44.     LL bi1 = b0;
  45.     for (int i = 1; i < 2 * m; i++) {
  46.         LL bi = (z * bi1 + t + (1 << 30)) % (1 << 30);
  47.         c[i] = bi % n;
  48.         bi1 = bi;
  49.     }
  50.     if (m > 0) {
  51.         c[0] = b0 % n;
  52.     }
  53.     LL ans = 0;
  54.     for (int i = 0; i < 2 * m; i += 2) {
  55.         int x = min(c[i], c[i + 1]) - 1;
  56.         if (x < 0) {
  57.             ans += sum[min(1ll * n - 1, max(c[i], c[i + 1]))];
  58.         } else {
  59.             ans += sum[min(1ll * n - 1, max(c[i], c[i + 1]))] - sum[x];
  60.         }
  61.     }
  62.     cout << ans;
  63. }
  64.  
  65. int main() {
  66.     ios_base::sync_with_stdio(0);
  67.     cin.tie(nullptr); cout.tie(nullptr);
  68.     /// =========================================
  69.     /// fin("input.txt"); fout("output.txt");
  70.     /// fin("file.in"); fout("file.out");
  71.     /// cin >> TN;
  72.     /// =========================================
  73.     while (TN--) solve();
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement