Submission #474512

# Submission time Handle Problem Language Result Execution time Memory
474512 2021-09-18T17:36:11 Z Alexandruabcde Peru (RMI20_peru) C++14
0 / 100
1 ms 468 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;
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 ) {
        while (!D.empty() && v[D.back()] < v[i]) {
            val[D.back()] = -1;
            D.pop_back();
        }

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

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

        if (!D.empty()) {
            val[D.front()] = v[D.front()] + dp[i-k];
            H.push({val[D.front()], D.front()});
        }

        D.push_back(i);

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

        dp[i] = H.top().first;
    }

    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 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -