Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ll u;
- struct DSU
- {
- vector<int> par, rank;
- int m;
- void build()
- {
- par.resize(m);
- rank.resize(m);
- for (int i = 0; i < m; i++)
- make(i);
- }
- int find(int v) { return ((v == par[v]) ? v : par[v] = find(par[v])); }
- void paint(int l, int r, int col)
- {
- for (int i = l;;)
- {
- i = find(i);
- if (i >= r) return;
- u += col;
- par[i] = i + 1;
- }
- }
- };
- DSU b;
- int a[20000000], c[10000000];
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie();
- cout.tie();
- //freopen("input.txt", "r", stdin);
- //freopen("output.txt", "w", stdout);
- int n, m, k, x, y, z;
- cin >> n >> m >> a[1] >> a[2] >> c[1] >> x >> y >> z;
- b.m = n + 9;
- b.build();
- for (int i = 3; i <= 2 * m; i++)
- a[i] = (x * 1ll * a[i - 2] + y * 1ll * a[i - 1] + z) % n + 1;
- for (int i = 2; i <= m; i++)
- c[i] = (x * 1ll * c[i - 1] + z * 1ll * y) % n + 1;
- for (int i = m; i > 0; i--)
- b.paint(min(a[i * 2 - 1], a[i * 2]), max(a[i * 2 - 1], a[i * 2]) + 1, c[i]);
- cout << u;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement