Submission #1012982

# Submission time Handle Problem Language Result Execution time Memory
1012982 2024-07-03T04:09:06 Z Nurislam Triple Jump (JOI19_jumps) C++17
0 / 100
26 ms 34908 KB
///*                                                    __                    __                        __                    */
///*        ======     _      /| /|  __   _            /   |  |   /|  |   *  |    |  |  | /   /| |\  | /   |  |  * | /        */
///* \-       ||  |_| |_     / |/ | |  | |_  |-        |   |--|  /-|  |   |  \ \  |==|  |-   /=| | \ | |   |--|  | |-         */
///*          ||  | | |_    /     | |__|  _| |_        \__ |  | /  |  |__ |  __|  |  |  | \ /  | |  \| \__ |  |  | | \        */
///* 
// autor :: Rick Prime
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long

const int N = 1e6+3, inf = 1e18, mod = 1e9+7;

int n, q;
vector<pair<int,int> > qu;
int sp[22][N];
int ans[5001][5001];
int get(int l, int r){
	int bt = __lg(r-l);
	return max(sp[bt][l], sp[bt][r-(1<<bt)+1]);
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		int x;
		cin >> x;
		sp[0][i] = x;
	}
	
	cin >> q;
	for(int i = 0; i < q; i++){
		int l, r;
		cin >> l >> r;
		qu.pb({l, r});
	}
	
	for(int i = 1; i < 22; i++){
		int len = (1 << (i-1));
		for(int j = 1; j <= n; j++){
			sp[i][j] = max(sp[i-1][j], sp[i-1][min(n,j+len)]);
		}
	}
	if(n <= 5000){
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				ans[i][j] = 0;
			}
		}
		for(int i = 1; i <= n; i++){
			for(int j = i+2; j <= n; j++){
				int mid = i + ((j-i) >> 1);
				ans[i][j] = sp[0][i] + sp[0][j] + get(i+1, mid);
				ans[i][j] = max(ans[i][j], ans[i][j-1]);
			}
		}
		for(int j = n; j > 0; j--){
			for(int i = j-1; i > 0; i--){
				ans[i][j] = max(ans[i][j], ans[i+1][j]);
			}
		}
		for(auto [l, r] :qu)cout << ans[l][r] << '\n';
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 34908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -