Submission #535546

# Submission time Handle Problem Language Result Execution time Memory
535546 2022-03-10T13:14:50 Z keta_tsimakuridze Peru (RMI20_peru) C++14
0 / 100
1 ms 340 KB
#include<bits/stdc++.h>
#include "peru.h"
using namespace std;
 
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define endl "\n"
 
const int N = 2e5 + 5, mod = 1e9 + 7; //!
int t;
void add(int &a, int c) {
	a += c;
	if(a >= mod) a -= mod;
}
int solve(int n, int k, int *x) {
	vector<int> a(n + 1), p(n + 1);
	vector<ll> dp(n + 1);
	for(int i = 0; i < n; i++) a[i + 1] = x[i];
	deque<pii> st;
	deque<pair<ll,int> > X;
	p[0] = 1;
	for(int i = 1; i <= n - 1; i++) p[i] = (ll)p[i - 1] * 23 % mod;
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(st.size() && st.front().s < i - k + 1) {
			pii x = st.front();
			if(X.size() && X.front().s == x.f) X.pop_front();
			st.front().s++; 
			x.s++;
			if(x.s> x.f) st.pop_front();
			else {
				X.push_front({dp[x.s - 1] + a[x.f], x.f});
			}
		}
		int l = i;
		while(st.size() && a[st.back().f] < a[i]) {
			l = st.back().s;
			if(X.size() && X.back().s == st.back().f ) X.pop_back();
			st.pop_back();
		}
		st.push_back({i, l}); 
		ll x = a[i] + dp[l - 1];
		X.push_back({x, i});	
		dp[i] = X.front().f;
		add(ans, (ll)dp[i] % mod * p[n - i] % mod);
	
	}
	return ans;
}
/*
static int s[N];
int main() {
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> s[i];
	cout << solve(n, k, s);
}*/
# 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 -