Submission #1104862

#TimeUsernameProblemLanguageResultExecution timeMemory
1104862RiverFlowPermutation (APIO22_perm)C++17
65.26 / 100
9 ms1456 KiB
#include <bits/stdc++.h>

#define nl "\n"
#define no "NO"
#define yes "YES"
#define fi first
#define se second
#define vec vector
#define task "main"
#define _mp make_pair
#define ii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define evoid(val) return void(std::cout << val)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
#define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin())

using namespace std;

template<typename U, typename V> bool maxi(U &a, V b) {
    if (a < b) { a = b; return 1; } return 0;
}
template<typename U, typename V> bool mini(U &a, V b) {
    if (a > b) { a = b; return 1; } return 0;
}

const int N = (int)2e5 + 9;
const int mod = (int)1e9 + 7;

#define ll long long

vec<int> ans;

const long long LG = 59;
void build(long long k) {
    if (k == 0) return ;
    if (k == 1) {
        ans.push_back(1);
        return ;
    }
    long long sum = 0;
    FOR(i, 1, LG) if (1 & k >> i) {
        ans.push_back(i);
        sum += (1LL << i) - 1;
    }
    build(k - sum);
}
vector<int> construct_permutation(long long k)
{
    ans.clear();
    build(k - 1);
    vec<int> res;
    int sum = 0;
    for(int x : ans) sum += x;
    for(int x : ans) {
        int t = sum - x + 1;
        FOR(j, 0, x - 1)
            res.push_back(t + j - 1);
        sum -= x;
    }
	return res;
}



/*     Let the river flows naturally     */


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...