Advertisement
Jaydeep999997

Chef and Queries

Mar 30th, 2021
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const long long mod = 1LL << 32;
  5. const long long M = (1LL << 31);
  6.  
  7. bitset<M> b;
  8.  
  9. signed main()
  10. {
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(NULL); cout.tie(NULL);
  13.  
  14.     int q;
  15.     long long S, A, B;
  16.     cin >> q >> S >> A >> B;
  17.     long long ans = 0;
  18.     for (int i = 1; i <= q; i++)
  19.     {
  20.         long long val = (S >> 1);
  21.         if (S & 1)
  22.         {
  23.             if (b[val] == 0)
  24.             {
  25.                 ans += val;
  26.             }
  27.             b[val] = 1;
  28.         }
  29.         else
  30.         {
  31.             if (b[val] == 1)
  32.             {
  33.                 ans -= val;
  34.             }
  35.             b[val] = 0;
  36.         }
  37.         S = (A * S + B) % mod;
  38.     }
  39.     cout << ans << "\n";
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement