답안 #489493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
489493 2021-11-23T04:04:43 Z fhvirus 3단 점프 (JOI19_jumps) C++17
0 / 100
4000 ms 17668 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef pair<int, int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define AI(x) begin(x),end(x)
template<class I> bool chmin(I&a, I b){ return a > b ? (a=b, true) : false; }
template<class I> bool chmax(I&a, I b){ return a < b ? (a=b, true) : false; }
#ifdef OWO
#define debug(args...) LKJ("\033[1;32m[ " + string(#args) + " ]\033[0m", args)
template<class I> void LKJ(I&&x){ cerr << x << endl; }
template<class I, class...T> void LKJ(I&&x, T&&...t){ cerr << x << ", "; LKJ(t...); }
template<class I> void OI(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a; }
#else
#define debug(...) 0
#define OI(...) 0
#endif

const int kL = 20;
const int kN = 500005;
const int kQ = 500005;
int N, Q, A[kN];
int L[kQ], R[kQ];

void input(){
	cin >> N;
	for(int i = 1; i <= N; ++i)
		cin >> A[i];
	cin >> Q;
	for(int i = 0; i < Q; ++i)
		cin >> L[i] >> R[i];
}

int suf[kN];
int sp[kL][kN];
void init(){
	for(int i = N; i >= 1; --i)
		suf[i] = max(suf[i+1], A[i]);
	for(int i = 1; i <= N; ++i)
		sp[0][i] = A[i];
	for(int l = 1; l < kL; ++l)
		for(int i = 1; i <= N; ++i)
			sp[l][i] = max(sp[l-1][i], sp[l-1][i+(1<<(l-1))]);
}
int query(int l, int r){
	int d = __lg(r-l+1);
	return max(sp[d][l], sp[d][r-(1<<d)+1]);
}
int f(int a, int c){
	return A[a] + query(a+1, (a+c)/2) + suf[c];
}

int best[kN], bval[kN];
void solve(){
	init();
	for(int i = 1; i <= N-2; ++i){
		int l = i+2, r = N, m;
		while(l < r){
			m = (l+r) / 2;
			if(f(i, m) >= f(i, m+1)) r = m-1;
			else l = m;
		}
		best[i] = l;
		bval[i] = f(i, l);
	}

	int ans = 0;
	for(int i = 1; i <= N-2; ++i)
		ans = max(ans, bval[i]);
	cout << ans << '\n';
}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	input();
	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Execution timed out 4059 ms 460 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Execution timed out 4059 ms 460 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4064 ms 17668 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 460 KB Output is correct
2 Execution timed out 4059 ms 460 KB Time limit exceeded
3 Halted 0 ms 0 KB -