Submission #138320

# Submission time Handle Problem Language Result Execution time Memory
138320 2019-07-29T18:16:06 Z qkxwsm Triple Jump (JOI19_jumps) C++14
27 / 100
59 ms 21096 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 1000000007
#define MAXN 5300013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, Q;
int arr[MAXN];
int sparse[20][MAXN];
vpi cand;
vpi pos;
int ans;

int query(int l, int r)
{
	if (l > r) return -INF;
	int sz = 31 - __builtin_clz(r - l + 1);
	return max(sparse[sz][l], sparse[sz][r - (1 << sz) + 1]);
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	FOR(i, 0, N) cin >> arr[i];
	cin >> Q;
	FOR(i, 0, N)
	{
		sparse[0][i] = arr[i];
	}
	FOR(i, 0, 20)
	{
		FOR(j, 0, N)
		{
			if (j + (1 << i) < N)
			{
				sparse[i + 1][j] = max(sparse[i][j], sparse[i][j + (1 << i)]);
			}
		}
	}
	//everything in between (l..r) must be less than a[l] and a[r]
	//find all (l..r) such that everything between them is <= them
	FORD(i, N, 0)
	{
		int x = arr[i];
		while(!pos.empty() && pos.back().fi <= arr[i])
		{
			cand.PB({i, pos.back().se});
			pos.pop_back();
		}
		if (!pos.empty())
		{
			cand.PB({i, pos.back().se});
		}
		pos.PB({x, i});
	}
	for (pii p : cand)
	{
		int a = p.fi, b = p.se;
		// cerr << a << ' ' << b << endl;
		ckmax(ans, arr[a] + arr[b] + query(2 * b - a, N - 1));
	}
	cout << ans << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 21096 KB Output is correct
2 Correct 53 ms 20192 KB Output is correct
3 Correct 52 ms 19088 KB Output is correct
4 Correct 58 ms 21096 KB Output is correct
5 Correct 57 ms 21096 KB Output is correct
6 Correct 51 ms 20452 KB Output is correct
7 Correct 50 ms 20456 KB Output is correct
8 Correct 51 ms 20300 KB Output is correct
9 Correct 54 ms 20684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -