Submission #855757

# Submission time Handle Problem Language Result Execution time Memory
855757 2023-10-01T18:07:09 Z TimDee Peru (RMI20_peru) C++17
49 / 100
600 ms 174308 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 sz = 1<<22;
int sz=1;
struct node {
	int ans=inf, mina=inf;
	int32_t maxb=0, minb=0;
};

//node t[sz];
//int32_t lazy[sz];
//int dp[sz];
//int32_t b[sz];
vector<node> t;
vector<int32_t> lazy, b;
vector<int> dp;
void merge(int v) {
	if (2*v+2 >= sz-1) {
		t[v].ans = min(dp[2*v+1-sz+1]+b[2*v+1-sz+1], dp[2*v+2-sz+1]+b[2*v+2-sz+1]);
		t[v].mina = min(dp[2*v+1-sz+1], dp[2*v+2-sz+1]);
		t[v].minb = min(b[2*v+1-sz+1], b[2*v+2-sz+1]);
		t[v].maxb = max(b[2*v+1-sz+1], b[2*v+2-sz+1]);
		if (t[v].minb == t[v].maxb) t[v].ans=min(t[v].ans, t[v].maxb + t[v].mina);
		return;
	}
	t[v].ans = min(t[2*v+1].ans, t[2*v+2].ans);
	t[v].mina = min(t[2*v+1].mina, t[2*v+2].mina);
	t[v].maxb = max(t[2*v+1].maxb, t[2*v+2].maxb);
	t[v].minb = min(t[2*v+1].minb, t[2*v+2].minb);
	if (t[v].minb == t[v].maxb) t[v].ans=min(t[v].ans, t[v].maxb + t[v].mina);
}
int32_t x;
void push(int v) {
	x = lazy[v];
	lazy[v]=0;
	if (2*v+2<sz-1) {
		lazy[2*v+1] = max(lazy[2*v+1],x);
		lazy[2*v+2] = max(lazy[2*v+2],x);
	} else {
		b[2*v+1-sz+1]=max(b[2*v+1-sz+1],x);
		b[2*v+2-sz+1]=max(b[2*v+2-sz+1],x);
	}
	t[v].minb = t[v].maxb = x;
	t[v].ans = t[v].mina + x;
}

void Set(int i) {
	int v = (sz+i-2)>>1;
	while (v > 0) {
		merge(v);
		v = (v-1)>>1;
	}
	merge(0);
}
void upd(int v, int l, int r, int lx, int rx, int x) {
	if (r-l==1) {
		if (rx<=l || r<=lx) return;
		if (b[v-sz+1] >= x) return;
		b[v-sz+1] = x;
		return;
	}
	if (lazy[v]) push(v);
	if (t[v].minb >= x) return;
	if (rx<=l || r<=lx) return;
	if (lx<=l && r<=rx) {
		if (t[v].maxb <= x) {
			lazy[v] = x;
			push(v);
			return;
		}
	}
	int m=(l+r)>>1;
	upd(2*v+1,l,m,lx,rx,x);
	upd(2*v+2,m,r,lx,rx,x);
	merge(v);
}
void upd(int l, int r, int x) {
	upd(0,0,sz,l,r,x);
}
int query(int v, int l, int r, int lx, int rx) {
	if (r-l==1) {
		if (rx<=l || r<=lx) return inf;
		return dp[v-sz+1]+b[v-sz+1];
	}
	if (lazy[v]) push(v);
	if (rx<=l || r<=lx) return inf;
	if (lx<=l && r<=rx) return t[v].ans;
	int m=(l+r)>>1;
	int lq = query(2*v+1,l,m,lx,rx);
	int rq = query(2*v+2,m,r,lx,rx);
	return min(lq,rq);
}
int query(int l, int r) {
	return query(0,0,sz,l,r);
}

int32_t solve(int32_t n, int32_t k, int32_t* a) {
	if (n==1) return a[0]%mod;

	while (sz<n) sz<<=1;
	t.resize(sz);
	b.resize(sz);
	dp.resize(sz);
	lazy.resize(sz);
   	
	forn(i,n+1) dp[i]=inf;
	dp[0]=0;
	Set(0);
	for (int i=1; i<=n; ++i) {
		upd(0,i,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 2 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 232 ms 23316 KB Output is correct
16 Correct 229 ms 23380 KB Output is correct
17 Correct 229 ms 23312 KB Output is correct
18 Correct 239 ms 23320 KB Output is correct
19 Correct 247 ms 23320 KB Output is correct
20 Correct 234 ms 23132 KB Output is correct
21 Correct 228 ms 23376 KB Output is correct
22 Correct 228 ms 23316 KB Output is correct
23 Correct 244 ms 23316 KB Output is correct
24 Correct 228 ms 23376 KB Output is correct
25 Correct 226 ms 23316 KB Output is correct
26 Correct 225 ms 23128 KB Output is correct
27 Correct 242 ms 23312 KB Output is correct
28 Correct 229 ms 23316 KB Output is correct
29 Correct 237 ms 23316 KB Output is correct
30 Correct 224 ms 23132 KB Output is correct
31 Correct 224 ms 23132 KB Output is correct
32 Correct 257 ms 23320 KB Output is correct
33 Correct 218 ms 23312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 232 ms 23316 KB Output is correct
2 Correct 229 ms 23380 KB Output is correct
3 Correct 229 ms 23312 KB Output is correct
4 Correct 239 ms 23320 KB Output is correct
5 Correct 247 ms 23320 KB Output is correct
6 Correct 234 ms 23132 KB Output is correct
7 Correct 228 ms 23376 KB Output is correct
8 Correct 228 ms 23316 KB Output is correct
9 Correct 244 ms 23316 KB Output is correct
10 Correct 228 ms 23376 KB Output is correct
11 Correct 226 ms 23316 KB Output is correct
12 Correct 225 ms 23128 KB Output is correct
13 Correct 242 ms 23312 KB Output is correct
14 Correct 229 ms 23316 KB Output is correct
15 Correct 237 ms 23316 KB Output is correct
16 Correct 224 ms 23132 KB Output is correct
17 Correct 224 ms 23132 KB Output is correct
18 Correct 257 ms 23320 KB Output is correct
19 Correct 218 ms 23312 KB Output is correct
20 Correct 2 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Execution timed out 1049 ms 174308 KB Time limit exceeded
35 Halted 0 ms 0 KB -