Submission #441633

#TimeUsernameProblemLanguageResultExecution timeMemory
441633Vladth11Peru (RMI20_peru)C++14
100 / 100
540 ms72880 KiB
#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 << " " #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 <ll> dq; int solve(int n, int k, int* v) { ll sol = 0; for(ll i = 0; i < n; i++) a[i + 1] = v[i]; put[0] = 1; for(ll i = 1; i <= n; i++) { put[i] = put[i - 1] * 23; put[i] %= MOD; } multiset <ll> st; for(ll 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, 0LL)] + a[dq.front()]); //dp[i] %= MOD; } else { dp[i] = dp[max(0LL, i - k)] + a[dq.front()]; //dp[i] %= MOD; } sol += ((dp[i] % MOD) * put[n - i]) % MOD; sol %= MOD; } return sol; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...