답안 #1116286

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116286 2024-11-21T12:35:17 Z Dan4Life 3단 점프 (JOI19_jumps) C++17
0 / 100
42 ms 68268 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
#define int long long
const int N = (int)5e5+10;
const int LINF = (int)2e18;
const int LG = 20;
int n, q, mx[LG][N];
array<int,2> a[N];
 
int rmq(int l, int r){
	if(l>r) return -LINF;
	int lg = __lg(r-l+1);
	return max(mx[lg][l], mx[lg][r-(1<<lg)+1]);
}

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n; int ans = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i][0];
		a[i][1] = i; mx[0][i]=a[i][0];
	}
	for(int j = 1; j < LG; j++)
		for(int i = 1; i+(1<<j)-1 <= n; i++)
			mx[j][i] = max(mx[j-1][i],mx[j-1][i+(1<<(j-1))]);
	sort(a+1,a+n+1); reverse(a+1,a+n+1);
	int xd = min(n,LG+5);
	for(int i = 1; i <= xd; i++){
		for(int j = i+1; j <= xd; j++){
			for(int k = j+1; k <= xd; k++){
				vector<int> v; v.clear();
				v.pb(a[i][1]); v.pb(a[j][1]); v.pb(a[k][1]);
				sort(all(v));
				if(v[1]-v[0]<=v[2]-v[1]) 
					ans = max(ans, a[i][0]+a[j][0]+a[k][0]);
			}
		}
	}
	for(int i = 1; i <= xd; i++){
		for(int j = i+1; j <= xd; j++){
			vector<int> v; v.clear();
			v.pb(a[i][1]); v.pb(a[j][1]);
			sort(all(v));
			int l = v[0], r = v[1],sum=a[i][0]+a[j][0];
			// k after r 
			ans = max(ans, sum+rmq(r+r-l,n));

			// k before l 
			ans = max(ans, sum+rmq(max(1ll,l-(r-l)),l-1));

			// k inside l..r
			if(r-l>=2) ans = max(ans, sum+rmq(l+1,(r+l)/2));
		}
	}

	for(int i = 1; i <= xd; i++){
		//it can be middle?
		//it can be first?
		//it can be second?
	}
	cin >> q;
	while(q--){
		int l, r; cin >> l >> r;
		cout << ans << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Incorrect 2 ms 14672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Incorrect 2 ms 14672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 68176 KB Output is correct
2 Correct 30 ms 68176 KB Output is correct
3 Correct 26 ms 68176 KB Output is correct
4 Correct 42 ms 68176 KB Output is correct
5 Correct 40 ms 68176 KB Output is correct
6 Incorrect 38 ms 68268 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Incorrect 2 ms 14672 KB Output isn't correct
3 Halted 0 ms 0 KB -