Advertisement
Georgiy031

Untitled

Sep 16th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5. #define all(x) x.begin(), x.end()
  6. #define rall(x) x.rbegin(), x.rend()
  7. ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
  8. ll fac(ll a) { return (a ? a * fac(a - 1) : 1); }
  9.  
  10. int n, p, q, m;
  11. unsigned int SA, SB, SC;
  12. vector<unsigned int> v, maxx;
  13. unsigned int res = 0;
  14.  
  15. unsigned int rng61() {
  16.     SA ^= SA << 16;
  17.     SA ^= SA >> 5;
  18.     SA ^= SA << 1;
  19.     unsigned int t = SA;
  20.     SA = SB;
  21.     SB = SC;
  22.     SC ^= t ^ SA;
  23.     return SC;
  24.    
  25. }
  26. void gen() {
  27.    cin >> n >> p >> q >> m >> SA >> SB >> SC;
  28.  
  29.    v.clear();
  30.    maxx.clear();
  31.    maxx.reserve(n);
  32.    v.reserve(n);
  33.    res = 0;
  34.     for (int i = 1; i <= n; i++) {
  35.         if (rng61() % (p + q) < p) {
  36.             unsigned int t = rng61() % m + 1;
  37.             v.push_back(t);
  38.             if (maxx.size() == 0) maxx.push_back(t);
  39.             else maxx.push_back(max<unsigned int>(t, maxx.back()));
  40.         }
  41.         else if(v.size() > 0) {
  42.             maxx.pop_back();
  43.             v.pop_back();
  44.         }
  45.        
  46.         unsigned int t;
  47.         if (maxx.size() > 0)
  48.             t = maxx.back();
  49.         else t = 0;
  50.  
  51.         res ^= i * t;
  52.     }
  53. }
  54. signed main() {
  55.  
  56.     ios_base::sync_with_stdio(false);
  57.     cin.tie(nullptr);
  58.     cout.tie(nullptr);
  59.    
  60.     int cur_q = 1, max_q;
  61.     cin >> max_q;
  62.     while (cur_q <= max_q) {
  63.         gen();
  64.         cout << "Case #" << cur_q << ": " << res << "\n";
  65.         ++cur_q;
  66.     }
  67.    
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement