Submission #983499

# Submission time Handle Problem Language Result Execution time Memory
983499 2024-05-15T15:15:21 Z Faisal_Saqib Permutation (APIO22_perm) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vll vector<ll>
vector<int> cp(ll k)// O(lg n)
{
    vector<int> ans;
    ll n_req=0;
    ll hb=-1;
    for(int j=59;j>=0;j--)
    {
        ll pw=(1ll<<j);
        if(k&pw)
        {
            if(hb==-1)
            {
                n_req+=j;
                hb=j;
            }
            else
                n_req++;
        }
    }
    ll last=n_req-1;
    int first=0;
    // cout<<last<<endl;
    for(int l=0;l<60 and l<hb;l++)
    {
        if(k&(1ll<<l))
        {
            ans.push_back(first);
            first++;
        }
        if(first<=last)
        {
            ans.push_back(last);
            last--;
        }
    }
    reverse(begin(ans),end(ans));
    return ans;
}
ll task(ll n) // O(lg n)
{
    ll cp=0;
    for(int bit=59;bit>=0;bit--)
    {
        if(n&(1ll<<bit))
        {
            cp+=bit;
            n^=(1ll<<bit);
            break;
        }
    }
    while(n)
    {
        cp++;
        n-=(n&-n);
    }
    return cp;
}
vector<int> construct_permutation(ll k)
{
    // vector<int> ans=cp(k);
    ll mx=task(k);
    ll a=-1;
    ll b=n;
    // if(mx<90)
    // {
    //     return ans;
    // }
    ll SQ=6e5;
    for(ll d=1;d<=SQ;d++)
    {
        if(k%d==0)
        {
            ll f=task(d);
            ll s=task(k/d);
            if((f+s)<mx)
            {
                mx=f+s;
                a=d;
                b=k/d;
            }
        }
    }
    if(a==-1)
    {
        return cp(k);
    }
    else{
        vll ap=cp(a);
        vll bp=cp(b);
        ll nm=ap.size();
        for(auto i:bp)
            ap.pb(i+nm);
        return ap;
    }
    return {};
}
// int main()
// {
//     int n;
//     cin>>n;
//    auto tp= construct_permutation(n);
//    for(auto k:tp)
//    {
//     cout<<k<<' ';
//    }
//    cout<<endl;
// }

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:69:10: error: 'n' was not declared in this scope
   69 |     ll b=n;
      |          ^
perm.cpp:94:18: error: conversion from 'vector<int>' to non-scalar type 'vector<long long int>' requested
   94 |         vll ap=cp(a);
      |                ~~^~~
perm.cpp:95:18: error: conversion from 'vector<int>' to non-scalar type 'vector<long long int>' requested
   95 |         vll bp=cp(b);
      |                ~~^~~
perm.cpp:99:16: error: could not convert 'ap' from 'vector<long long int>' to 'vector<int>'
   99 |         return ap;
      |                ^~
      |                |
      |                vector<long long int>