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>
#include "perm.h"
using namespace std;
vector<int> construct_permutation(long long m)
{
long long k = m;
if (k == 2) return {0};
if (k == 3) return {1, 0};
stack<int> ops; //0 -> *2, 1 -> +1, 2 -> +2, 3 -> +3
while (((k>>4)&1) || k >= (1<<5)-1)
{
if ((k&3) == 3) ops.push(3), ops.push(0), ops.push(0), k>>=2;
else if ((k&1) == 1) ops.push(1), ops.push(0), ops.push(0), k>>=2;
else ops.push(0), k>>=1;
}
if (k == 0b0100) ops.push(1);
if (k == 0b0101) ops.push(2);
if (k == 0b0110) ops.push(3);
if (k == 0b0111) ops.push(3), ops.push(1);
if (k == 0b1000) ops.push(0), ops.push(1);
if (k == 0b1001) ops.push(1), ops.push(0), ops.push(1);
if (k == 0b1010) ops.push(0), ops.push(2);
if (k == 0b1011) ops.push(3), ops.push(0), ops.push(1);
if (k == 0b1100) ops.push(0), ops.push(0);
if (k == 0b1101) ops.push(1), ops.push(0), ops.push(0);
if (k == 0b1110) ops.push(0), ops.push(1), ops.push(0);
if (k == 0b1111) ops.push(3), ops.push(0), ops.push(0);
// long long sum = 3;
// while (ops.size()) sum = sum*(ops.top() == 0? 2 : 1) + ops.top(), ops.pop();
// return sum;
vector<int> a = {1, 0};
while (ops.size())
{
int op = ops.top(); ops.pop();
if (op == 0) a.push_back(a.size());
if (op == 1)
{
vector<int> temp = a;
a.clear(), a.push_back(temp.size());
for (auto i : temp) a.push_back(i);
}
if (op == 2)
{
vector<int> temp = a;
a.clear(), a.push_back(temp[0]), a.push_back(temp.size());
for (auto i : temp) if (i != temp[0]) a.push_back(i);
}
if (op == 3)
{
for (auto &i : a) if (i >= 2) i++;
a.push_back(2);
}
}
return a;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |