Submission #855874

# Submission time Handle Problem Language Result Execution time Memory
855874 2023-10-02T06:14:35 Z TimDee Peru (RMI20_peru) C++17
49 / 100
600 ms 126408 KB
//  Esti <3

//\
     šťastia pre nás :)
//   you're already the best
//             _
//   ^ ^      //
// >(O_O)<___//
//   \ __ __  \
//    \\ \\ \\\\
 
#include <bits/stdc++.h>
using namespace std;
 
//#pragma GCC optimize("O3","unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")

using ll = long long;
#define int long long
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
 
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll inf = 1e18;
const ll mod = 1e9+7;//998244853;

// \
\
:smiling_face_with_3_hearts: :smiling_face_with_3_hearts:  :smiling_face_with_3_hearts:  
 
//vidime sa veľmi skoro, moje slnko

const int N=25e5+5;
int dp[N];
int t[2*N];
int lazy[2*N];

void updup(int v) {
	v>>=1;
	while(v) {
		t[v]=min(t[v<<1],t[(v<<1)|1])+lazy[v];
		v>>=1;
	}
}
void updv(int v, int x) {
	t[v]+=x;
	lazy[v]+=x;
}
void push(int v) {
	for (int i=22; i; --i) {
		int u = v>>i;
		if ((u) && lazy[u]) {
			updv(u<<1,lazy[u]);
			updv((u<<1)|1,lazy[u]);
			lazy[u]=0;
		}
	}
}
void Set(int i) {
	i+=N;
	t[i]=dp[i-N];
	updup(i);
}
void upd(int l, int r, int x) {
	l+=N, r+=N;
	int lq=l, rq=r;
	while (l<r) {
		if (l&1) {
			updv(l++,x);
		}
		if (r&1) {
			updv(--r,x);
		}
		l>>=1, r>>=1;
	}
	updup(lq);
	updup(rq-1);
}
int query(int l, int r) {
	l+=N, r+=N;
	push(l);
	push(r-1);
	int ans = inf;
	while (l<r) {
		if (l&1) {
			ans=min(ans,t[l++]);
		}
		if (r&1) {
			ans=min(ans,t[--r]);
		}
		l>>=1;
		r>>=1;
	}
	return ans;
}

int32_t solve(int32_t n, int32_t k, int32_t* a) {
	if (n==1) return a[0]%mod;	
   	
	forn(i,n+1) dp[i]=inf;
	forn(i,2*N) t[i]=inf;
	dp[0]=0;
	Set(0);
	vector<pi> st={ {0,inf} };
	for (int i=1; i<=n; ++i) {
		while (st.back().s <= a[i-1]) {
			int r = st.back().f;
			int x = st.back().s;
			st.pop_back();
			int l = st.back().f;
			upd(l,r,-x);
		}
		int l = st.back().f;
		int r = i;
		upd(l,r,a[i-1]);
		st.pb({r,a[i-1]});

		int x = query(max(i-k,0ll),i);
		dp[i] = x;
		Set(i);
	}

	int ans=0, p=1;
	for (int i=n; i; --i) {
		dp[i]%=mod;
		ans=(ans+p*dp[i])%mod;
		p=(p*23)%mod;
	}
	return ans;

}

Compilation message

peru.cpp:3:1: warning: multi-line comment [-Wcomment]
    3 | //\
      | ^
peru.cpp:9:1: warning: multi-line comment [-Wcomment]
    9 | //   \ __ __  \
      | ^
peru.cpp:36:1: warning: multi-line comment [-Wcomment]
   36 | // \
      | ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 47708 KB Output is correct
2 Correct 6 ms 47784 KB Output is correct
3 Correct 6 ms 47708 KB Output is correct
4 Correct 7 ms 47656 KB Output is correct
5 Correct 7 ms 47704 KB Output is correct
6 Correct 7 ms 47708 KB Output is correct
7 Correct 6 ms 47676 KB Output is correct
8 Correct 6 ms 47720 KB Output is correct
9 Correct 7 ms 47632 KB Output is correct
10 Correct 7 ms 47708 KB Output is correct
11 Correct 6 ms 47708 KB Output is correct
12 Correct 7 ms 47708 KB Output is correct
13 Correct 6 ms 47708 KB Output is correct
14 Correct 7 ms 47640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 47708 KB Output is correct
2 Correct 6 ms 47784 KB Output is correct
3 Correct 6 ms 47708 KB Output is correct
4 Correct 7 ms 47656 KB Output is correct
5 Correct 7 ms 47704 KB Output is correct
6 Correct 7 ms 47708 KB Output is correct
7 Correct 6 ms 47676 KB Output is correct
8 Correct 6 ms 47720 KB Output is correct
9 Correct 7 ms 47632 KB Output is correct
10 Correct 7 ms 47708 KB Output is correct
11 Correct 6 ms 47708 KB Output is correct
12 Correct 7 ms 47708 KB Output is correct
13 Correct 6 ms 47708 KB Output is correct
14 Correct 7 ms 47640 KB Output is correct
15 Correct 151 ms 59476 KB Output is correct
16 Correct 148 ms 59584 KB Output is correct
17 Correct 154 ms 59712 KB Output is correct
18 Correct 157 ms 59308 KB Output is correct
19 Correct 158 ms 59220 KB Output is correct
20 Correct 165 ms 59388 KB Output is correct
21 Correct 151 ms 60880 KB Output is correct
22 Correct 152 ms 60872 KB Output is correct
23 Correct 158 ms 60872 KB Output is correct
24 Correct 148 ms 60740 KB Output is correct
25 Correct 149 ms 60868 KB Output is correct
26 Correct 154 ms 60824 KB Output is correct
27 Correct 150 ms 60708 KB Output is correct
28 Correct 158 ms 60940 KB Output is correct
29 Correct 155 ms 61008 KB Output is correct
30 Correct 154 ms 60692 KB Output is correct
31 Correct 148 ms 60628 KB Output is correct
32 Correct 152 ms 60944 KB Output is correct
33 Correct 144 ms 60880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 59476 KB Output is correct
2 Correct 148 ms 59584 KB Output is correct
3 Correct 154 ms 59712 KB Output is correct
4 Correct 157 ms 59308 KB Output is correct
5 Correct 158 ms 59220 KB Output is correct
6 Correct 165 ms 59388 KB Output is correct
7 Correct 151 ms 60880 KB Output is correct
8 Correct 152 ms 60872 KB Output is correct
9 Correct 158 ms 60872 KB Output is correct
10 Correct 148 ms 60740 KB Output is correct
11 Correct 149 ms 60868 KB Output is correct
12 Correct 154 ms 60824 KB Output is correct
13 Correct 150 ms 60708 KB Output is correct
14 Correct 158 ms 60940 KB Output is correct
15 Correct 155 ms 61008 KB Output is correct
16 Correct 154 ms 60692 KB Output is correct
17 Correct 148 ms 60628 KB Output is correct
18 Correct 152 ms 60944 KB Output is correct
19 Correct 144 ms 60880 KB Output is correct
20 Correct 6 ms 47708 KB Output is correct
21 Correct 6 ms 47784 KB Output is correct
22 Correct 6 ms 47708 KB Output is correct
23 Correct 7 ms 47656 KB Output is correct
24 Correct 7 ms 47704 KB Output is correct
25 Correct 7 ms 47708 KB Output is correct
26 Correct 6 ms 47676 KB Output is correct
27 Correct 6 ms 47720 KB Output is correct
28 Correct 7 ms 47632 KB Output is correct
29 Correct 7 ms 47708 KB Output is correct
30 Correct 6 ms 47708 KB Output is correct
31 Correct 7 ms 47708 KB Output is correct
32 Correct 6 ms 47708 KB Output is correct
33 Correct 7 ms 47640 KB Output is correct
34 Execution timed out 934 ms 126408 KB Time limit exceeded
35 Halted 0 ms 0 KB -