QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132681#149. Perusomethingnew#0 34ms11816kbC++204.2kb2023-07-31 02:17:232024-09-10 16:40:42

Judging History

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

  • [2024-09-10 16:40:42]
  • 管理员手动重测本题所有提交记录
  • 测评结果:0
  • 用时:34ms
  • 内存:11816kb
  • [2024-07-04 01:02:23]
  • 评测
  • 测评结果:0
  • 用时:199ms
  • 内存:42732kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-31 02:17:23]
  • 提交

answer

//  ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
//  ➡ @roadfromroi ⬅
//  ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#include "queue"
#include "peru.h"
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
struct stackmax {
    vector<pair<int, int>> stk;
    int getval() {
        if (stk.empty())
            return 0;
        return stk.back().second;
    }
    void push(int x) {
        if (stk.empty())
            stk.push_back({x, x});
        else
            stk.push_back({x, max(x, stk.back().second)});
    }
    int pop() {
        int vl = stk.back().first;
        stk.pop_back();
        return vl;
    }
    bool empty() {
        return stk.empty();
    }
};
struct queuemax {
    stackmax a, b;
    int getval() {
        return max(a.getval(), b.getval());
    }
    void push(int x) {
        b.push(x);
    }
    void pop() {
        if (a.empty()) {
            while (!b.empty())
                a.push(b.pop());
        }
        a.pop();
    }
};
struct stackmin {
    vector<pair<ll, ll>> stk;
    ll getval() {
        if (stk.empty())
            return 1e18;
        return stk.back().second;
    }
    void push(ll x) {
        if (stk.empty())
            stk.push_back({x, x});
        else
            stk.push_back({x, min(x, stk.back().second)});
    }
    ll pop() {
        ll vl = stk.back().first;
        stk.pop_back();
        return vl;
    }
    bool empty() {
        return stk.empty();
    }
};
struct queuemin {
    stackmin a, b;
    ll getval() {
        return min(a.getval(), b.getval());
    }
    void push(ll x) {
        b.push(x);
    }
    void pop() {
        if (a.empty()) {
            while (!b.empty())
                a.push(b.pop());
        }
        a.pop();
    }
    bool empty() {
        return a.empty() and b.empty();
    }
};
int solve(int n, int k, int* v){
    vector<ll> dp(n + 1);
    dp[0] = 0;
    queuemax qmx;
    vector<int> nxtmr(n);
    for (int i = 0; i < n; ++i) {
        qmx.push(v[i]);
        if (i >= k) {
            nxtmr[i-k] = qmx.getval();
            qmx.pop();
        }
    }
    stackmin stk;
    queuemin que;
    queue<int> ind;
    for (int i = n; i < n + k; ++i) {
        nxtmr[i-k] = qmx.getval();
        qmx.pop();
    }
    int glbbeb = 0;
    vector<pair<int, pair<int, int>>> st1;
    for (int i = 0; i < n; ++i) {
        while (!st1.empty() and st1.back().first <= v[i]) {
            st1.pop_back();
            stk.pop();
        }
        int bep = 0;
        if (st1.empty()) {
            bep = max(glbbeb, i - k + 1);
        } else {
            bep = st1.back().second.second + 1;
        }
        if (st1.empty()) {
            while (nxtmr[bep] == v[i] and bep <= i) {
                que.push(v[i] + dp[bep]);
                ind.push(bep);
                bep++;
            }
            glbbeb = bep;
        }
        while (!ind.empty() and ind.front() + k < i + 1) {
            ind.pop();
            que.pop();
        }
        if (bep <= i) {
            st1.push_back({v[i], {bep, i}});
            //cout << "I " << i << endl;
            //for (auto t : st1)
            //    cout << t.first << ' ' << "{" << t.second.first << ' ' << t.second.second << "}\n";
            //cout << i << ' ' << st1.back().second.first << '\n';
            stk.push(v[i] + dp[st1.back().second.first]);
        }
        dp[i + 1] = min(que.getval(), stk.getval());
    }
    ll res = 0;
    ll mod = 1e9 + 7;
    ll tomlt = 1;
    for (int i = n; i > 0; --i) {
        res += dp[i] * tomlt % mod;
        tomlt = tomlt * 23 % mod;
    }
    for (int i = 0; i < n; ++i) {
       cout << dp[i + 1] << ' ';
    }
    cout << endl;
    return res % mod;
}
#ifdef __APPLE__
static int s[2500005];
static int n, k;
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    int ans = solve(n, k, s);
    cout << ans << "\n";
    return 0;
}
#endif

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3816kb

input:

2000 170
1054018657 1037445664 1011691297 1009972317 1006506677 1002579733 999792775 999477541 975467893 970302369 968173111 957735623 953086083 938540451 932313113 930563895 924682633 917831575 913506401 908739591 905368525 899452913 894354220 890127447 885923007 583391543 880642788 878397752 87822...

output:

1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 1054018657 105...

result:

wrong answer 1st lines differ - expected: '559335223', found: '1054018657 1054018657 10540186...09299203 7409299203 7409299203 '

Subtask #2:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 34ms
memory: 11816kb

input:

400000 1000
1999989721 1999987224 1999984551 1999977673 1999977545 1999976801 1999975837 1999972607 1999956301 1999952801 1999942489 1999940593 1999940337 1999936353 1999936273 1999926073 1999925513 1999922980 1999918301 1999912501 1999909301 1999906125 1999902913 1999895622 1999893617 1999885490 19...

output:

1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 1999989721 199...

result:

wrong answer 1st lines differ - expected: '677928817', found: '1999989721 1999989721 19999897...2665 737262992665 737262992665 '

Subtask #3:

score: 0
Time Limit Exceeded

Test #34:

score: 0
Time Limit Exceeded

input:

2500000 2000
1073315871 1073250349 1072791751 1072104046 1072071097 1071841833 1071809381 1071710686 1071580105 1071482003 1071383725 1071154701 1070499431 1070335288 1070334157 1069943617 1069681476 1069584279 1069581771 1069322519 1069189353 1069125955 1068832186 1068797487 1068662939 1068565681 1...

output:

1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 1073315871 107...

result: