QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#405565#7613. Inverse Problemucup-team3215Compile Error//C++205.0kb2024-05-06 07:17:372024-05-06 07:17:38

Judging History

你现在查看的是最新测评结果

  • [2024-05-06 07:17:38]
  • 评测
  • [2024-05-06 07:17:37]
  • 提交

answer

#include <algorithm>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

constexpr int mod = 1e9 + 7;

auto& mul(auto&& a, auto b) { return a = a * (uint64_t) b % mod; }
int inv(int a) { for (int r = 1, b = mod - 2; ; b /= 2, mul(a, a)) if (!b) return r; else if (b % 2) mul(r, a); }

using namespace std;

struct HT {
  static constexpr int mlf = 4;
  int cap;
  vector<array<int, 2>> knx;
  vector<int> from, values, head;

  HT(): cap{4 * mlf - 1}, head(cap + 1, -1) {
  }

  void emplace(int k, const vector<int>& v) {
    knx.push_back({k, head[k & cap]});
    from.push_back(values.size());
    values.insert(values.end(), v.begin(), v.end());
    head[k & cap] = knx.size() - 1;
    maybe_rehash();
  }

  int find(int k) {
    for (int i = head[k & cap]; ~i; i = knx[i][1]) if (knx[i][0] == k) return i;
    return -1;
  }

  void clear() {
    knx.clear();
    from.clear();
    values.clear();
    head.assign(cap + 1, -1);
  }

  void maybe_rehash() {
    if (knx.size() * mlf <= cap) return;
    head.assign((cap += cap + 1) + 1, -1);
    for (int i = 0; i < knx.size(); ++i) {
      knx[i][1] = head[knx[i][0] & cap];
      head[knx[i][0] & cap] = i;
    }
  }
};

vector<HT> high(1);
vector<int> inv_(1);

void gen_high(const vector<int>& prof, int n0, int n, int c, int p, auto&& cur) {
  high[n0 - n].emplace(p, cur);
  for (c = min(n, c); c > prof[n]; --c) {
    int np = p;
    for (int i = 0; i < c; ++i) mul(np, inv_[n0 - i]);
    cur.push_back(c);
    gen_high(prof, n0, n - c, c, np, cur);
    cur.pop_back();
  }
}

vector<int> qs;
vector<vector<int>> ans;

void solve(const vector<int>& prof, int n0, int n, int c, int p, auto&& cur) {
  for (int i = 0; i < qs.size(); ++i) if (ans[i].empty() && ~high[n0 - n].find(mul(+p, qs[i]))) {
    ans[i] = cur;
    auto t = high[n0 - n].find(mul(+p, qs[i]));
    ans[i].insert(ans[i].end(), high[n0 - n].values.begin() + high[n0 - n].from[t], t + 1 == high[n0 - n].from.size()? high[n0 - n].values.end(): high[n0 - n].values.begin() + high[n0 - n].from[t + 1]);
  }
  int i = 0;
  for (; n + c <= n0 && c <= prof[n + c]; ++c) {
    for (; i < c; ++i) mul(p, n0 - i);
    cur.push_back(c);
    solve(prof, n0, n + c, c, p, cur);
    cur.pop_back();
  }
}

uint64_t eval_high(vector<int> profile) {
  int N = profile.size();
  vector<uint64_t> cnt(N * N);
  cnt[N * N - 1] = 1;
  uint64_t ans = 0;
  for (int n = N; --n; )
  for (int c = N; --c; ) if (cnt[n * N + c]) {
    for (int cc = min(n, c); cc > profile[n]; cc--) {
      cnt[(n - cc) * N + cc] += cnt[n * N + c];
    }
    ans += cnt[n * N + c];
  }
  return ans;
}

uint64_t eval_low(vector<int> profile) {
  int N = profile.size();
  vector<uint64_t> cnt(N * N);
  cnt[0] = 1;
  uint64_t ans = 0;
  for (int n = 0; n < N; ++n)
  for (int c = 0; c <= n; ++c) if (cnt[n * N + c]) {
    for (int cc = max(c, 1); n + cc < N && cc <= profile[n + cc]; ++cc) {
      cnt[(n + cc) * N + cc] += cnt[n * N + c];
    }
    ans += cnt[n * N + c];
  }
  return ans;
}

uint64_t eval(vector<int> profile) {
  return eval_high(profile) * 2 + eval_low(profile);
}

vector<int> makeprof(int n, vector<int> from) {
  vector<int> prof(n + 1, 0);
  int j = n;
  for (int i = 0; i < from.size() - 1; ++i) {
    while (j >= from[i]) prof[j--] = i;
  }
  while (j >= 0) prof[j--] = n;
  return prof;
}

vector<int> getopt(int n) {
  static vector<vector<int>> precalc = [] {
    int n = 124;
    vector<vector<int>> res(n);
    vector<int> tmpl(10, n);
    while (n-- > 1) {
      int64_t bst = eval(makeprof(n, tmpl));
      for (int ch = 1; ch--; ) {
        for (int i = 1; i < tmpl.size() - 1; ++i)
        for (auto d: {-1, 1}) if (tmpl[i] + d >= 0 && tmpl[i] + d <= n + 1) {
          tmpl[i] += d;
          int64_t cur = eval(makeprof(n, tmpl));
          if (cur > bst) tmpl[i] -= d;
          else if (cur < bst) ch = 1, bst = cur;
          sort(tmpl.rbegin() + 1, tmpl.rend());
        }
      }
      res[n] = tmpl;
    }
    return res;
  }();
  return makeprof(n, precalc[n]);
}

int main() {
  int tc; cin >> tc;
  qs.resize(tc);
  ans.resize(tc);
  for (int i = 0; i < tc; ++i) {
    qs[i] = i + 1;
    if (qs[i] == 1) ans[i] = {-1};
    else if (qs[i] == 2) ans[i] = {-1};
    qs[i] = inv(qs[i]);
  }
  for (int n = 1, done = 0; !done++; ++n) {
    inv_.push_back(inv(n));
    high.push_back({});
    for (auto& x: high) x.clear();
    gen_high(getopt(n), n, n, n, 1, vector<int>{});
    solve(getopt(n), n, 0, 1, mul(n + 1, n + 2), vector<int>{});
    for (int i = 0; i < tc; ++i) done &= !ans[i].empty();
  }
  for (int i = 0; i < tc; ++i) {
    if (qs[i] == 1) cout << "1\n";
    else {
      if (ans[i][0] == -1) ans[i] = {};
      cout << accumulate(ans[i].begin(), ans[i].end(), 0) + 2 << "\n1 2\n";
      for (int j = 0, k = 2; j < ans[i].size(); ++j)
      while (ans[i][j]--) cout << j + 1 << ' ' << ++k << '\n';
    }
  }
}

Details

answer.code: In member function ‘void HT::emplace(int, const std::vector<int>&)’:
answer.code:26:18: error: no matching function for call to ‘std::vector<std::array<int, 2> >::push_back(<brace-enclosed initializer list>)’
   26 |     knx.push_back({k, head[k & cap]});
      |     ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/vector:66,
                 from answer.code:5:
/usr/include/c++/13/bits/stl_vector.h:1278:7: note: candidate: ‘constexpr void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::array<int, 2>; _Alloc = std::allocator<std::array<int, 2> >; value_type = std::array<int, 2>]’
 1278 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1278:35: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::vector<std::array<int, 2> >::value_type&’ {aka ‘const std::array<int, 2>&’}
 1278 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_vector.h:1295:7: note: candidate: ‘constexpr void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::array<int, 2>; _Alloc = std::allocator<std::array<int, 2> >; value_type = std::array<int, 2>]’
 1295 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/13/bits/stl_vector.h:1295:30: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::vector<std::array<int, 2> >::value_type&&’ {aka ‘std::array<int, 2>&&’}
 1295 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
answer.code: In member function ‘int HT::find(int)’:
answer.code:34:47: error: no match for ‘operator[]’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type’ {aka ‘std::array<int, 2>’} and ‘int’)
   34 |     for (int i = head[k & cap]; ~i; i = knx[i][1]) if (knx[i][0] == k) return i;
      |                                               ^
answer.code:34:62: error: no match for ‘operator[]’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type’ {aka ‘std::array<int, 2>’} and ‘int’)
   34 |     for (int i = head[k & cap]; ~i; i = knx[i][1]) if (knx[i][0] == k) return i;
      |                                                              ^
answer.code: In member function ‘void HT::maybe_rehash()’:
answer.code:49:13: error: no match for ‘operator[]’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type’ {aka ‘std::array<int, 2>’} and ‘int’)
   49 |       knx[i][1] = head[knx[i][0] & cap];
      |             ^
answer.code:49:30: error: no match for ‘operator[]’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type’ {aka ‘std::array<int, 2>’} and ‘int’)
   49 |       knx[i][1] = head[knx[i][0] & cap];
      |                              ^
answer.code:50:18: error: no match for ‘operator[]’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 2> >, std::array<int, 2> >::value_type’ {aka ‘std::array<int, 2>’} and ‘int’)
   50 |       head[knx[i][0] & cap] = i;
      |                  ^
/usr/include/c++/13/bits/stl_vector.h: In instantiation of ‘constexpr std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = std::array<int, 2>; _Alloc = std::allocator<std::array<int, 2> >]’:
/usr/include/c++/13/bits/stl_vector.h:528:7:   required from here
/usr/include/c++/13/bits/stl_vector.h:367:49: error: invalid use of incomplete type ‘struct std::array<int, 2>’
  367 |                       _M_impl._M_end_of_storage - _M_impl._M_start);
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/bits/uses_allocator_args.h:38,
                 from /usr/include/c++/13/bits/memory_resource.h:41,
                 from /usr/include/c++/13/string:58,
                 from /usr/include/c++/13/bits/locale_classes.h:40,
                 from /usr/include/c++/13/bits/ios_base.h:41,
                 from /usr/include/c++/13/ios:44,
                 from /usr/include/c++/13/ostream:40,
                 from /usr/include/c++/13/iostream:41,
                 from answer.code:3:
/usr/include/c++/13/tuple:2005:45: note: declaration of ‘struct std::array<int, 2>’
 2005 |   template<typename _Tp, size_t _Nm> struct array;
      |                                             ^~~~~
/usr/include/c++/13/bits/stl_vector.h: In instantiation of ‘constexpr std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = std::array<int, 2>; _Alloc = std::allocator<std::array<int, 2> >; size_type = long unsigned int]’:
answer.code:29:29:   required from here
/usr/include/c++/13/bits/stl_vector.h:990:50: error: invalid use of incomplete type ‘struct std::array<int, 2>’
  990 |       { return s...