Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- using namespace std;
- typedef long long ll;
- vector<ll> a, c, next, ans;
- int main(){
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- ll n, m, x, y, z, a1, a2, c1;
- cin >> n >> m;
- for (ll i = 1; i <= n; i++){
- next.pb(i);
- ans.pb(0);
- }
- cin >> a1 >> a2 >> c1;
- a.pb(a1);
- a.pb(a2);
- c.pb(c1);
- cin >> x >> y >> z;
- for (ll i = 2; i < 2 * m; i++)
- a.pb((x * a[i - 2] + y * a[i - 1] + z) % n + 1);
- for (ll i = 1; i < m; i++)
- c.pb((x * c[i - 1] + y * z) % n + 1);
- for (ll i = m; i >= 1; i--){
- ll l = a[i * 2 - 2], r = a[i * 2 - 1];
- if (l > r) swap(l, r);
- for (ll j = l - 1; j < r;)
- if (!ans[j]){
- ans[j] = c[i - 1];
- int p = j;
- j = next[j];
- next[p] = r;
- }
- else
- j = next[j];
- }
- for (ll i = 0; i < n; i++)
- cout << ans[i] << " ";
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement