Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- // tiom4eg's precompiler options
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- // IO settings
- #define fastIO ios_base::sync_with_stdio(false); cin.tie(0)
- // Quick types
- #define ll long long
- #define pii pair <int, int>
- #define pll pair <ll, ll>
- #define vi vector <int>
- #define mi vector <vector <int> >
- // Quick functions
- #define endl "\n"
- #define F first
- #define S second
- #define all(a) a.begin(), a.end()
- #define sz(a) a.size()
- #define pb push_back
- #define mp make_pair
- // Quick fors
- #define FOR(i, a, b) for (int i = a; i < b; ++i)
- #define RFOR(i, a, b) for (int i = a; i >= b; --i)
- // Pragmas
- #pragma GCC optimize("O3,unroll-loops") // let the chaos begin!
- //#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt,tune=native")
- #pragma GCC comment(linker, "/stack:200000000")
- // PBDS
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- #define ordered_set tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update>
- #define ook order_of_key
- #define fbo find_by_order
- // POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS POGGERS
- using namespace std;
- using namespace __gnu_pbds;
- mt19937 rng(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count());
- int randint(int n) { // [0; n)
- return rng() % n;
- }
- /*
- ██▓ ███▄ ▄███▓ ▄▄▄ ▒█████
- ▓██▒ ▓██▒▀█▀ ██▒▒████▄ ▒██▒ ██▒
- ▒██░ ▓██ ▓██░▒██ ▀█▄ ▒██░ ██▒
- ▒██░ ▒██ ▒██ ░██▄▄▄▄██ ▒██ ██░
- ░██████▒▒██▒ ░██▒ ▓█ ▓██▒░ ████▓▒░
- ░ ▒░▓ ░░ ▒░ ░ ░ ▒▒ ▓▒█░░ ▒░▒░▒░
- ░ ░ ▒ ░░ ░ ░ ▒ ▒▒ ░ ░ ▒ ▒░
- ░ ░ ░ ░ ░ ▒ ░ ░ ░ ▒
- ░ ░ ░ ░ ░ ░ ░
- */
- const int ITER = 50000;
- vi cnt, rcnt, a;
- int n, cur = 0;
- void gen() {
- vi p(n); FOR(i, 0, n) p[i] = i;
- FOR(i, 0, n) {
- int k = randint(n - i);
- a[i] = p[k];
- p.erase(p.begin() + k);
- }
- }
- // all in O(1)
- int f(int p) { return cnt[p + a[p]] + rcnt[2 * (n - 1) - a[p] - (n - p - 1)] - 2; }
- void add(int p) { cnt[p + a[p]]++, rcnt[2 * (n - 1) - a[p] - (n - p - 1)]++; }
- void del(int p) { cnt[p + a[p]]--, rcnt[2 * (n - 1) - a[p] - (n - p - 1)]--; }
- void change(int p1, int p2) {
- cur -= 2 * (f(p1) + f(p2));
- del(p1);
- del(p2);
- swap(a[p1], a[p2]);
- add(p1);
- add(p2);
- cur += 2 * (f(p1) + f(p2));
- }
- int main() {
- cin >> n;
- FOR(att, 0, 100) {
- cur = 0;
- cnt.assign(2 * n, 0);
- rcnt.assign(2 * n, 0);
- a.resize(n);
- gen();
- FOR(i, 0, n) add(i);
- FOR(i, 0, n) cur += f(i);
- FOR(i, 0, ITER) {
- if (!cur) break;
- int now = cur;
- int p1 = randint(n), p2 = randint(n);
- while (p2 == p1) p2 = randint(n);
- change(p1, p2);
- if (cur > now) change(p1, p2);
- }
- if (!cur) {
- for (auto& x : a) cout << x + 1 << ' ';
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement