# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
916434 | Jakub_Wozniak | Permutation (APIO22_perm) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
vector <pair<int,int>> V;
vector<int> construct_permutation(long long n)
{
long long MAX = 300;
vector <int> v;
vector <bool> B;
int R = n%3;
int r[200];
n /= 3;
if(R)v.push_back(R);
while (n)
{
if(n < 4)
{
if(n < 2)break;
if (n % 4 == 3) v.push_back(1);
v.push_back(MAX);
MAX--;
break;
}
if (n % 4 == 1) v.push_back(1);
if (n % 4 == 3) v.push_back(3);
v.push_back(MAX);
MAX--;
if (n % 4 == 2) v.push_back(1);
v.push_back(MAX);
MAX--;
n /= 4;
}
v.push_back(1);
v.push_back(2);
reverse(v.begin() , v.end());
for(int i = 0 ; i < v.size() ; i++)
{
V.push_back({v[i],-i});
}
sort(V.begin() , V.end());
long long akt = 0;
for(int i = 0 ; i < V.size() ;i++)
{
r[-V[i].second] = akt;
akt++;
}
for(int i = 0 ; i < V.size() ; i++)
{
v[i] = r[i];
}
V.clear();
return v;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
long long t, n, m, f, xa, ya, xb, yb;
cin >> t;
while (t--)
{
cin >> n;
vector <int> k = construct_permutation(n);
cout << k.size() << '\n';
for(int i= 0 ; i < k.size() ; i++)
{
cout << k[i] << ' ';
}
cout << '\n';
}
return 0;
}