Submission #746373

# Submission time Handle Problem Language Result Execution time Memory
746373 2023-05-22T12:04:09 Z doowey Peru (RMI20_peru) C++14
0 / 100
1 ms 468 KB
#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];
bool off[N];
int pos[N];


int solve(int n, int k, int* v){
    A[0] = (ll)1e18;
    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;
    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()){
            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);
    }
    int chum = 0;
    int pw = 1;
    for(int i = n; i >= 1; i -- ){
        //cout << dp[i] << " ";
        chum += (pw * 1ll * dp[i]) % MOD;
        if(chum >= MOD) chum -= MOD;
        pw = (pw * 23ll) % MOD;
    }
    return chum;
}
# 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 -