Submission #855725

# Submission time Handle Problem Language Result Execution time Memory
855725 2023-10-01T17:16:30 Z TimDee Peru (RMI20_peru) C++17
49 / 100
235 ms 262144 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

struct sgt {
	struct node {
		int ans=inf, full=1, mina=0, maxb=0, minb=0;
	};
	node merge(node a, node b) {
		node ret;
		ret.ans = min(a.ans, b.ans);
		ret.full = (a.full && b.full) && (a.maxb == b.maxb);
		ret.mina = min(a.mina, b.mina);
		ret.maxb = max(a.maxb, b.maxb);
		ret.minb = min(a.minb, b.minb);
		if (ret.full) ret.ans=min(ret.ans, ret.maxb + ret.mina);

		return ret;
	}
	void push(int v) {
		int x = lazy[v];
		lazy[v]=0;
		lazy[2*v+1] = max(lazy[2*v+1],x);
		lazy[2*v+2] = max(lazy[2*v+2],x);
		t[v].minb = t[v].maxb = x;
		//cout<<"? "<<v<<' '<<t[v].mina<<' '<<t[v].ans<<' '<<x<<'\n';
		t[v].ans = t[v].mina + x;
		t[v].full = 1;
	}

	vector<node> t; int sz=1;
	vector<int> lazy;

	sgt(int n) {
		while (sz<n) sz<<=1;
		t.resize(2*sz);
		lazy.resize(4*sz);
	}
	void set(int i, int x) {
		t[sz-1+i].mina = x;
		t[sz-1+i].ans = x + t[sz-1+i].maxb;
		int v = (sz+i-2)>>1;
		while (v > 0) {
			t[v] = merge(t[2*v+1],t[2*v+2]);
			v = (v-1)>>1;
		}
		t[0] = merge(t[1],t[2]);
	}
	void upd(int v, int l, int r, int lx, int rx, int x) {
		//cout<<"Upd "<<v<<' '<<l<<' '<<r<<' '<<lx<<' '<<rx<<' '<<x<<'\n';
		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);
				//cout<<"! "<<t[v].ans<<' '<<t[v].mina<<' '<<t[v].full<<' '<<t[v].minb<<' '<<t[v].maxb<<'\n';
				return;
			}
			assert(r-l > 1);
		}
		int m=(l+r)>>1;
		upd(2*v+1,l,m,lx,rx,x);
		upd(2*v+2,m,r,lx,rx,x);
		t[v]=merge(t[2*v+1],t[2*v+2]);
	}
	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 (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;
   	
   	sgt st(n+1);
   	st.set(0,0);
	vector<int> dp(n+1,inf);
	dp[0]=0;
	for (int i=1; i<=n; ++i) {
		st.upd(0,i,a[i-1]);
		int x = st.query(max(i-k,0ll),i);
		dp[i] = x;
		st.set(i,x);
		//cout<<dp[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 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 217 ms 63320 KB Output is correct
16 Correct 211 ms 63372 KB Output is correct
17 Correct 210 ms 63320 KB Output is correct
18 Correct 230 ms 63324 KB Output is correct
19 Correct 227 ms 63320 KB Output is correct
20 Correct 235 ms 63324 KB Output is correct
21 Correct 227 ms 67448 KB Output is correct
22 Correct 215 ms 67408 KB Output is correct
23 Correct 214 ms 67452 KB Output is correct
24 Correct 214 ms 67608 KB Output is correct
25 Correct 209 ms 67412 KB Output is correct
26 Correct 212 ms 67288 KB Output is correct
27 Correct 217 ms 67412 KB Output is correct
28 Correct 220 ms 67456 KB Output is correct
29 Correct 222 ms 67276 KB Output is correct
30 Correct 213 ms 67448 KB Output is correct
31 Correct 209 ms 67456 KB Output is correct
32 Correct 231 ms 67452 KB Output is correct
33 Correct 209 ms 67452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 63320 KB Output is correct
2 Correct 211 ms 63372 KB Output is correct
3 Correct 210 ms 63320 KB Output is correct
4 Correct 230 ms 63324 KB Output is correct
5 Correct 227 ms 63320 KB Output is correct
6 Correct 235 ms 63324 KB Output is correct
7 Correct 227 ms 67448 KB Output is correct
8 Correct 215 ms 67408 KB Output is correct
9 Correct 214 ms 67452 KB Output is correct
10 Correct 214 ms 67608 KB Output is correct
11 Correct 209 ms 67412 KB Output is correct
12 Correct 212 ms 67288 KB Output is correct
13 Correct 217 ms 67412 KB Output is correct
14 Correct 220 ms 67456 KB Output is correct
15 Correct 222 ms 67276 KB Output is correct
16 Correct 213 ms 67448 KB Output is correct
17 Correct 209 ms 67456 KB Output is correct
18 Correct 231 ms 67452 KB Output is correct
19 Correct 209 ms 67452 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 604 KB Output is correct
34 Runtime error 80 ms 262144 KB Execution killed with signal 9
35 Halted 0 ms 0 KB -