QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#116807#149. Peruhos_lyric#Compile Error//C++142.8kb2023-06-30 08:35:222024-05-31 18:29:41

Judging History

你现在查看的是测评时间为 2024-05-31 18:29:41 的历史记录

  • [2024-09-10 16:33:36]
  • 管理员手动重测本题所有提交记录
  • 测评结果:18
  • 用时:85ms
  • 内存:10104kb
  • [2024-05-31 18:29:41]
  • 评测
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-30 08:35:22]
  • 提交

answer

#include "peru.h"

#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 <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; }


constexpr int MO = 1'000'000'007;
constexpr Int INF = 1001001001001001001LL;

struct Entry {
  int pos;
  Int val;
};
struct Deque {
  deque<Entry> que;
  int size() const {
    return que.size();
  }
  Entry front() const {
    return que.front();
  }
  Entry back() const {
    return que.back();
  }
  void pushFront(const Entry &e) {
    que.push_front(e);
  }
  void pushBack(const Entry &e) {
    que.push_back(e);
  }
  void popFront() {
    que.pop_front();
  }
  void popBack() {
    que.pop_back();
  }
  Int get() const {
    Int mn = INF;
    for (const Entry &e : que) {
      chmin(mn, e.val);
    }
    return mn;
  }
  friend ostream &operator<<(ostream &os, const Deque &que) {
    os << "[ ";
    for (const Entry &e : que.que) {
      os << "(" << e.pos << "," << e.val << ") ";
    }
    os << "]";
    return os;
  }
};

int solve(int N, int K, int *S) {
  vector<Int> dp(N + 1, INF);
  dp[0] = 0;
  Deque que;
  for (int i = 0; i < N; ++i) {
    for (; que.size() && S[que.back().pos] <= S[i]; que.popBack()) {}
    {
      Entry e;
      e.pos = i;
      e.val = dp[que.size() ? (que.back().pos + 1) : 0] + S[i];
      que.pushBack(e);
    }
    for (; que.front().pos < i + 1 - K; que.popFront()) {}
// cerr<<que<<endl;
    assert(que.size());
    {
      const Entry e = que.front();
      que.popFront();
      chmin(dp[i + 1], que.get());
      chmin(dp[i + 1], dp[max(i + 1 - K, 0)] + S[e.pos]);
      que.pushFront(e);
    }
  }
// cerr<<"dp = "<<dp<<endl;
  
  Int ans = 0;
  for (int i = 1; i <= N; ++i) {
    ans = (ans * 23 + dp[i]) % MO;
  }
  return ans;
}

详细

implementer.cpp: In function ‘int main()’:
implementer.cpp:34:13: error: ‘fout’ was not declared in this scope; did you mean ‘out’?
   34 |     fprintf(fout, "%d\n", sol);
      |             ^~~~
      |             out
implementer.cpp: In function ‘char nextch()’:
implementer.cpp:15:31: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     if (pos == BUF_SIZE) fread(buf, BUF_SIZE, 1, fin), pos = 0;
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~