Submission #1116284

# Submission time Handle Problem Language Result Execution time Memory
1116284 2024-11-21T12:34:24 Z Dan4Life Triple Jump (JOI19_jumps) C++17
0 / 100
39 ms 69964 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-1);
	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));
		}
	}
	cin >> q;
	while(q--){
		int l, r; cin >> l >> r;
		cout << ans << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Incorrect 2 ms 14672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Incorrect 2 ms 14672 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 68340 KB Output is correct
2 Correct 27 ms 69724 KB Output is correct
3 Correct 25 ms 69964 KB Output is correct
4 Correct 38 ms 69724 KB Output is correct
5 Correct 39 ms 69844 KB Output is correct
6 Incorrect 38 ms 69516 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Incorrect 2 ms 14672 KB Output isn't correct
3 Halted 0 ms 0 KB -