Submission #912497

# Submission time Handle Problem Language Result Execution time Memory
912497 2024-01-19T14:41:01 Z linvg Permutation (APIO22_perm) C++17
Compilation error
0 ms 0 KB
#include "perm.h"

std::vector<int> construct_permutation(long long x)
{
    long long sum = 1;

    long long mn = 1e9 - 1;

    vector<long long> res;

    while (sum < x)
    {
        long long cnt = 0;
        for (long long i = 1; i <= 62; ++i)
        {
            if (sum + (1ll << i) - 1 > x)
            {
                sum += (1ll << (i - 1)) - 1;
                cnt = i - 1;
                break;
            }
        }
        // dbg(sum, cnt);
        for (long long i = mn - cnt; i < mn; ++i)
        {
            // cout << i << " ";
            res.pb(i);
        }
        mn -= cnt;

        for (long long i = 62; i >= 1; --i)
        {
            if (sum + (1ll << (i - 1)) <= x)
            {
                sum += (1ll << (i - 1));
                cnt = i - 1;
                res.pb(mn + cnt);
            }
        }
    }
    // dbg(sum);
    // dbg(sz(res));
    return res;
}

Compilation message

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:9:5: error: 'vector' was not declared in this scope
    9 |     vector<long long> res;
      |     ^~~~~~
perm.cpp:9:5: note: suggested alternatives:
In file included from /usr/include/c++/10/vector:67,
                 from perm.h:1,
                 from perm.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note:   'std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from perm.h:1,
                 from perm.cpp:1:
/usr/include/c++/10/vector:86:13: note:   'std::pmr::vector'
   86 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
perm.cpp:9:12: error: expected primary-expression before 'long'
    9 |     vector<long long> res;
      |            ^~~~
perm.cpp:27:13: error: 'res' was not declared in this scope
   27 |             res.pb(i);
      |             ^~~
perm.cpp:37:17: error: 'res' was not declared in this scope
   37 |                 res.pb(mn + cnt);
      |                 ^~~
perm.cpp:43:12: error: 'res' was not declared in this scope
   43 |     return res;
      |            ^~~