Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <set>
  4. #include <map>
  5. #include <vector>
  6. #include <string>
  7. using namespace std;
  8.  
  9. uint32_t x0, x1, a, b, c;
  10. const int basic = (1 << 31);
  11.  
  12. uint32_t next() {
  13. int32_t t = x0 * a + x1 * b + c;
  14. x0 = x1;
  15. x1 = t;
  16. return (x1 << 1) >> 1;
  17. }
  18.  
  19. signed main() {
  20. ios_base::sync_with_stdio(false);
  21. cin.tie(0);
  22. cout.tie(0);
  23. int n, k;
  24. cin >> n >> k >> x0 >> x1 >> a >> b >> c;
  25. vector<int> ans(2 * k, 0);
  26. int q = 0;
  27. for (int i = 0; i < n; i++) {
  28. int x = next();
  29. ans[q] = x;
  30. q++;
  31. if (q == k) {
  32. nth_element(ans.begin(), ans.begin() + k, ans.end());
  33. q = 0;
  34. }
  35. }
  36. nth_element(ans.begin(), ans.begin() + k, ans.end());
  37. vector<int> res(k);
  38. for (int i = k; i < 2 * k; i++)
  39. res[i - k] = ans[i];
  40. sort(res.begin(), res.end());
  41. reverse(res.begin(), res.end());
  42. for (int i = 0; i < res.size(); i++) {
  43. cout << res[i] << ' ';
  44. }
  45. cout << '\n';
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement