# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
441611 |
2021-07-05T14:38:47 Z |
Vladth11 |
Peru (RMI20_peru) |
C++14 |
|
1 ms |
340 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "peru.h"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 2500002;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 1000000007;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;
const ll LIMIT = 1000;
ll dp[NMAX];
ll a[NMAX];
ll put[NMAX];
deque <int> dq;
int solve(int n, int k, int* v) {
ll sol = 0;
for(int i = 0; i < n; i++)
a[i + 1] = v[i];
put[0] = 1;
for(int i = 1; i <= n; i++) {
put[i] = put[i - 1] * 23;
put[i] %= MOD;
}
multiset <ll> st;
for(int i = 1; i <= n; i++) {
while(dq.size() && dq.front() < i - k + 1) {
ll x = dp[dq.front()];
dq.pop_front();
if(dq.size()){
x += a[dq.front()];
auto it = st.find(x);
st.erase(it);
}
}
while(dq.size() && a[dq.back()] <= a[i]) {
ll x = a[dq.back()];
dq.pop_back();
if(dq.size()){
x += dp[dq.back()];
auto it = st.find(x);
st.erase(it);
}
}
if(dq.size())
st.insert(a[i] + dp[dq.back()]);
dq.push_back(i);
if(st.size()) {
dp[i] = min((ll)(*st.begin()), dp[max(i - k, 0)] + a[dq.front()]);
dp[i] %= MOD;
} else {
dp[i] = dp[max(0, i - k)] + a[dq.front()];
dp[i] %= MOD;
}
sol += (dp[i] * put[n - i]) % MOD;
sol %= MOD;
}
return sol;
}
# |
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 |
- |