Submission #746397

#TimeUsernameProblemLanguageResultExecution timeMemory
746397dooweyPeru (RMI20_peru)C++14
100 / 100
356 ms80152 KiB
#include <bits/stdc++.h>
#include "peru.h"

using namespace std;

typedef long long ll;
typedef pair<ll, int> pii;

#define fi first
#define se second
#define mp make_pair

const int N = 2511111;
const int MOD = (int)1e9 + 7;
ll dp[N];
ll A[N];
ll ndp[N];
bool off[N];
int pos[N];


int solve(int n, int k, int* v){
    for(int i = 1; i <= n; i ++ ){
        A[i] = v[i - 1];
    }
    priority_queue<pii, vector<pii>, greater<pii>> P;
    deque<pii> L;
    //L.push_back(mp(0, -1));
    int id = 0;
    ll mx;
    for(int i = 1; i <= n; i ++ ){

        while(!L.empty() && A[i] >= A[L.back().fi]){
            if(L.back().se != -1) off[L.back().se] = true;
            L.pop_back();
        }

        while(!L.empty() && L.front().fi <= i - k) {
            if(L.front().se != -1) off[L.front().se] = true;
            L.pop_front();
        }
        if(!L.empty()){
            off[L.back().se] = true;
            P.push(mp(A[i] + dp[L.back().fi], id));
            L.back().se = id;
            id ++ ;
        }
        L.push_back(mp(i, -1));
        dp[i] = dp[max(i - k, 0)] + A[L.front().fi];
        while(!P.empty() && off[P.top().se]) P.pop();
        if(!P.empty()) {
            dp[i] = min(dp[i], P.top().fi);
        }
        // -------------
        /*
        ndp[i] = (ll)1e18;
        mx = 0ll;
        for(int j = i ; j >= max(1, i - k + 1); j -- ){
            mx = max(mx, A[j]);
            ndp[i] = min(ndp[i], ndp[j - 1] + mx);
        }
        */
    }
    int chum = 0;
    int pw = 1;
    for(int i = n; i >= 1; i -- ){
        //cout << dp[i] << " ";
        dp[i] %= MOD;
        chum += (pw * 1ll * dp[i]) % MOD;
        if(chum >= MOD) chum -= MOD;
        pw = (pw * 23ll) % MOD;
    }
    return chum;
}

Compilation message (stderr)

peru.cpp: In function 'int solve(int, int, int*)':
peru.cpp:30:8: warning: unused variable 'mx' [-Wunused-variable]
   30 |     ll mx;
      |        ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...