QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423778#149. PerupppppCompile Error//C++203.9kb2024-05-28 16:23:492024-09-10 16:46:02

Judging History

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

  • [2024-09-10 16:46:02]
  • 管理员手动重测本题所有提交记录
  • [2024-05-28 16:23:50]
  • 评测
  • [2024-05-28 16:23:49]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef ngu
#include "debug.h"
#else
#define debug(...) 42
#endif

using ll = int64_t;

const int N = int(25e5) + 5, MOD = int(1e9) + 7;
const ll INF = ll(1e18);

int n, k;
int a[N], pw[N], le[N];
ll dp[N], cost[N], mn[N];
bool ri[N];

void add(int &x, int y) {
    if ((x += y) >= MOD) {
        x -= MOD;
    }
}

namespace st {
    int top = 0;
    int s[N];

    void push_back(int x) {
        s[++top] = x;
    }

    void pop_back() {
        top--;
    }

    int back() {
        return s[top];
    }

    int size() {
        return top;
    }

    void clear() {
        top = 0;
    }
}

namespace dq {
    int sz = 0, bot, top;
    int prv[N], nxt[N];

    void push_front(int x) {
        if (!sz) {
            bot = top = x;
        } else {
            prv[bot] = x;
            nxt[x] = bot;
            bot = x;
        }
        sz++;
    }

    void push_back(int x) {
        if (!sz) {
            bot = top = x;
        } else {
            prv[x] = top;
            nxt[top] = x;
            top = x;
        }
        sz++;
    }

    void pop_back() {
        top = prv[top];
        sz--;
    }

    void pop_front() {
        bot = nxt[bot];
        sz--;
    }

    int back() {
        return top;
    }

    int front() {
        return bot;
    }

    void clear() {
        sz = 0;
    }

    int size() {
        return sz;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    #ifdef ngu
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
    #endif
    cin >> n >> k;
    pw[0] = 1;
    for (int i = 1; i <= n; ++i) {
        pw[i] = ll(pw[i - 1]) * 23 % MOD;
        cost[i] = INF;
        cin >> a[i];
    }
    for (int i = n; i > 0; --i) {
        while (st::size() && a[st::back()] < a[i]) {
            st::pop_back();
        }
        int r = !st::size() ? n : st::back() - 1;
        st::push_back(i);
        ri[i] = min(i + k - 1, n) <= r;
    }
    st::clear();
    for (int i = 1; i <= n; ++i) {
        if (dq::size() && dq::front() == i - k) {
            dq::pop_front();
        }
        while (dq::size() && a[dq::back()] <= a[i]) {
            dq::pop_back();
        }
        dq::push_back(i);
        le[i] = dq::front();
    }
    dq::clear();
    for (int i = 1; i <= n; ++i) {
        while (st::size() && a[st::back()] <= a[i]) {
            st::pop_back();
        }
        if (dq::size() && dq::front() == i - k) {
            dq::pop_front();
        }
        int l = max(0, i - k), L = i;
        bool in = false;
        if (st::size()) {
            in = true;
            l = max(l, st::back());
            L = min(L, st::s[1]);
        }
        if (dq::size()) {
            in = true;
            l = max(l, dq::back());
            L = min(L, dq::front());
        }
        if (in) {
            cost[l] = dp[l] + a[i];
        }
        dp[i] = min(dp[l] + a[i], dp[max(0, i - k)] + a[le[i]]);
        if (dq::size()) {
            dp[i] = min(dp[i], cost[dq::front()]);
            dp[i] = min(dp[i], cost[dq::back()]);
        }
        if (st::size()) {
            dp[i] = min({dp[i], mn[st::back()], cost[st::back()]});
        }
        if (ri[i]) {
            if (dq::size()) {
                int x = dq::back();
                while (dq::size() && cost[dq::back()] >= cost[x]) {
                    dq::pop_back();
                }
                dq::push_back(x);
            }
            dq::push_back(i);
        } else {
            if (st::size()) {
                mn[i] = min(mn[st::back()], cost[st::back()]);
            } else {
                mn[i] = INF;
            }
            st::push_back(i);
        }
    }
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        add(res, dp[i] % MOD * pw[n - i] % MOD);
    }
    cout << res;
}

詳細信息

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;
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccLVTvKW.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/ccLz3nJW.o:implementer.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccLz3nJW.o: in function `main':
implementer.cpp:(.text.startup+0x151): undefined reference to `solve(int, int, int*)'
collect2: error: ld returned 1 exit status