fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. void _144()
  6. {
  7. ll n, k;
  8. cin >> n >> k;
  9.  
  10. ll x, a, b, c;
  11. cin >> x >> a >> b >> c;
  12.  
  13. vector<ll> nums(n + 1, 0);
  14. nums[1] = x;
  15. for (ll i = 2; i <= n; i++) nums[i] = (a * nums[i - 1] + b) % c;
  16.  
  17. ll ans = 0, curSum = 0;
  18.  
  19. //Handle the first window separately
  20. for (int i = 1; i <= k; i++) curSum += nums[i];
  21. ans ^= curSum;
  22.  
  23. //Handle remaining windows
  24. for (int i = k + 1; i <= n; i++)
  25. {
  26. int prev_el=nums[i-k];
  27. int next_el=nums[i];
  28.  
  29. curSum += next_el;
  30. curSum -= prev_el;
  31.  
  32. ans ^= curSum;
  33. }
  34.  
  35. cout << ans;
  36. return;
  37. }
  38.  
  39. int main()
  40. {
  41. ios_base::sync_with_stdio(false);
  42. cin.tie(NULL);
  43. cout.tie(NULL);
  44.  
  45. ll t = 1;
  46. while (t--)
  47. {
  48. _144();
  49. }
  50. }
Runtime error #stdin #stdout #stderr 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc