Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4.  
  5. using namespace std;
  6.  
  7. typedef long long ll;
  8.  
  9. vector<ll> a, c, next, ans;
  10.  
  11. int main(){
  12. ios::sync_with_stdio(0);
  13. cin.tie(0);
  14. cout.tie(0);
  15.  
  16. ll n, m, x, y, z, a1, a2, c1;
  17. cin >> n >> m;
  18. for (ll i = 1; i <= n; i++){
  19. next.pb(i);
  20. ans.pb(0);
  21. }
  22. cin >> a1 >> a2 >> c1;
  23. a.pb(a1);
  24. a.pb(a2);
  25. c.pb(c1);
  26. cin >> x >> y >> z;
  27. for (ll i = 2; i < 2 * m; i++)
  28. a.pb((x * a[i - 2] + y * a[i - 1] + z) % n + 1);
  29. for (ll i = 1; i < m; i++)
  30. c.pb((x * c[i - 1] + y * z) % n + 1);
  31. for (ll i = m; i >= 1; i--){
  32. ll l = a[i * 2 - 2], r = a[i * 2 - 1];
  33. if (l > r) swap(l, r);
  34. for (ll j = l - 1; j < r;)
  35. if (!ans[j]){
  36. ans[j] = c[i - 1];
  37. int p = j;
  38. j = next[j];
  39. next[p] = r;
  40. }
  41. else
  42. j = next[j];
  43. }
  44. for (ll i = 0; i < n; i++)
  45. cout << ans[i] << " ";
  46. cout << endl;
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement