Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define sz(x) ((int) (x).size())
- #define all(x) (x).begin(), (x).end()
- #define fi first
- #define se second
- #define mp make_pair
- #define push_back
- #define re return
- using ll = long long;
- using ull = unsigned long long;
- using ii = pair<int, int>;
- using vi = vector<int>;
- using vii = vector<ii>;
- using ld = long double;
- template <class T> T abs (T x) { re x > 0 ? x : -x; }
- template <class T> T sqr (T x) { re x * x; }
- const ld pi = acos(1.);
- const int inf = 1e9 + 7;
- const int N = 1e7;
- int n, m;
- unsigned int a[N], x, y, cur;
- unsigned int nextRand24() {
- cur = cur * x + y;
- return cur >> 8;
- }
- unsigned int nextRand32() {
- unsigned int a = nextRand24(), b = nextRand24();
- return (a << 8) ^ b;
- }
- unsigned int get (int l, int r, int k) {
- if (r - l < 100) {
- for (int i = l; i < r; i++)
- for (int j = i + 1; j <= r; j++)
- if (a[i] > a[j]) {
- swap (a[i], a[j]);
- }
- re a[l + k];
- }
- auto c = (l + r) >> 1;
- int pos = l;
- while (pos < c) {
- if (a[pos] > a[c]) {
- swap(a[pos], a[c - 1]);
- swap(a[c - 1], a[c]);
- c--;
- } else {
- pos++;
- }
- }
- pos = r;
- while (pos > c) {
- if (a[pos] < a[c]) {
- swap(a[pos], a[c + 1]);
- swap(a[c + 1], a[c]);
- c++;
- } else {
- pos--;
- }
- }
- if (c == k + l) re a[c];
- if (c > k + l) re get (l, c - 1, k);
- else re get (c + 1, r, k - c + l - 1);
- }
- int main() {
- cin >> n >> x >> y;
- for (int i = 0; i < n; i++) a[i] = nextRand32();
- ll mid = get (0, n - 1, n / 2);
- ll ans = 0;
- for (int i = 0; i < n; i++) ans += abs(a[i] - mid);
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement