Submission #641404

# Submission time Handle Problem Language Result Execution time Memory
641404 2022-09-16T15:41:08 Z Alexandruabcde Peru (RMI20_peru) C++14
0 / 100
1 ms 340 KB
#include "peru.h"
#include <iostream>
#include <deque>
#include <queue>
#include <vector>

using namespace std;

constexpr int NMAX = 2500005;
constexpr int MOD = 1e9 + 7;
typedef long long LL;
constexpr LL INF = 1LL * 1e16;
typedef pair <LL, int> PLI;

int ans = 0;
LL dp[NMAX];
int val[NMAX];

int solve(int n, int k, int* v){
    deque <int> D;
    priority_queue <PLI, vector<PLI>, greater<PLI> > H;
    for (int i = 0; i < n; ++ i ) {
        dp[i] = INF;

        while (!D.empty() && v[D.back()] <= v[i]) {
            val[D.back()] = -1;

            D.pop_back();
        }

        while (!D.empty() && D.front() <= i - k) {
            val[D.front()] = -1;

            D.pop_front();
        }

        D.push_back(i);

        if (!D.empty()) {
            val[D.front()] = v[D.front()] + (i - k < 0 ? 0 : dp[i - k]);

            H.push({val[D.front()], D.front()});
        }

        if (D.size() >= 2) {
            val[D.back()] = v[D.back()] + dp[D[D.size()-2]];

            H.push({val[D.back()], D.back()});
        }
        else {
            val[D.back()] = v[D.back()] + (i - k < 0 ? 0 : dp[i - k]);

            H.push({val[D.back()], D.back()});
        }

        while (!H.empty() && val[H.top().second] != H.top().first)
            H.pop();

        if (!H.empty()) dp[i] = H.top().first;
        else dp[i] = v[D.front()] + (i - k < 0 ? 0 : dp[i - k]);
    }

    for (int i = 0; i < n; ++ i )
        ans = (23LL * ans + dp[i] % MOD) % MOD;

    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -