QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749607#9540. Double 11hos_lyricCompile Error//C++143.8kb2024-11-15 06:37:312024-11-15 06:37:32

Judging History

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

  • [2024-11-15 06:37:32]
  • 评测
  • [2024-11-15 06:37:31]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


template <class T, class Cost> struct MonotoneMinDP {
  int n;
  Cost cost;
  vector<T> ts;
  vector<int> par;
  MonotoneMinDP() {}
  MonotoneMinDP(int n_, Cost cost_) : n(n_), cost(cost_) {
    ts.assign(n + 1, T());
    par.assign(n + 1, -1);
    update(0, n);
    rec(0, n);
  }
  void update(int l, int r) {
assert(l<r);
    const T t = ts[l] + cost(l, r);
    if (!~par[r] || ts[r] > t) {
      ts[r] = t;
      par[r] = l;
    }
  }
  // precondition: ts[0, l] is determined
  // precondition: transitions from [0, l] to r is checked
  // postcondition: ts[0, r] is determined
  void rec(int l, int r) {
    if (r - l <= 1) return;
    const int m = (l + r) / 2;
    for (int i = max(par[l], 0); i <= max(par[r], 0); ++i) update(i, m);
//!?
if(par[l]>par[r])check(par[l],m);
    rec(l, m);
    for (int i = l + 1; i <= m; ++i) update(i, r);
    rec(m, r);
  }
};
template <class T, class Cost> MonotoneMinDP<T, Cost> monotoneMinDP(int n, Cost cost) {
  return MonotoneMinDP<T, Cost>(n, cost);
}


template <class D, class F> auto goldenMax(D a, D b, int numIters, F f) {
  constexpr D GOLD = (3.0L - sqrt(5.0L)) / 2.0L;
  D c = a + GOLD * (b - a), d = b - GOLD * (b - a);
  auto fc = f(c), fd = f(d);
  for (int iter = 0; iter < numIters; ++iter) {
    if (fc < fd) { a = c; c = d; d = b - GOLD * (b - a); fc = fd; fd = f(d); }
    else         { b = d; d = c; c = a + GOLD * (b - a); fd = fc; fc = f(c); }
  }
  return make_pair(fc, c);
}


using Double = long double;

int N, M;
vector<Int> S;

int main() {
  for (; ~scanf("%d%d", &N, &M); ) {
    S.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%lld", &S[i]);
    }
    sort(S.begin(), S.end());
    
    vector<Int> SSum(N + 1, 0);
    for (int i = 0; i < N; ++i) {
      SSum[i + 1] = SSum[i] + S[i];
    }
    
    auto lag = [&](const Double pena) {
      return monotoneMinDP<Double>(N, [&](int l, int r) -> Double {
        return sqrt((Double)((r - l) * (SSum[r] - SSum[l]))) + pena;
      });
    };
    // cost <= sqrt(N SSum[N]) <= (2*10^5) * sqrt(10^5)
    const auto res = goldenMax(-2e8L, +2e8L, 200, [&](const Double pena) -> Double {
      const auto m = lag(pena);
      return m.ts[N] - M * pena;
    });
    const auto m = lag(res.second);
    Double ans = 0.0;
    for (int r = N; r; ) {
      const int l = m.par[r];
assert(0<=l);
assert(l<r);
assert(r<=N);
      ans += sqrt((Double)((r - l) * (SSum[r] - SSum[l])));
      r = l;
    }
    
    printf("%.20Lf\n", (long double)ans);
  }
  return 0;
}

详细

answer.code: In member function ‘void MonotoneMinDP<T, Cost>::rec(int, int)’:
answer.code:66:18: error: there are no arguments to ‘check’ that depend on a template parameter, so a declaration of ‘check’ must be available [-fpermissive]
   66 | if(par[l]>par[r])check(par[l],m);
      |                  ^~~~~
answer.code:66:18: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
answer.code: In instantiation of ‘void MonotoneMinDP<T, Cost>::rec(int, int) [with T = long double; Cost = main()::<lambda(Double)>::<lambda(int, int)>]’:
answer.code:48:5:   required from ‘MonotoneMinDP<T, Cost>::MonotoneMinDP(int, Cost) [with T = long double; Cost = main()::<lambda(Double)>::<lambda(int, int)>]’
answer.code:73:10:   required from ‘MonotoneMinDP<T, Cost> monotoneMinDP(int, Cost) [with T = long double; Cost = main()::<lambda(Double)>::<lambda(int, int)>]’
answer.code:108:35:   required from here
answer.code:66:23: error: ‘check’ was not declared in this scope
   66 | if(par[l]>par[r])check(par[l],m);
      |                  ~~~~~^~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:98:12: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   98 |       scanf("%lld", &S[i]);
      |       ~~~~~^~~~~~~~~~~~~~~