QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#640388#8577. 평균 최대화user10086Compile Error//C++172.7kb2024-10-14 11:39:202024-10-14 11:39:20

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 11:39:20]
  • 评测
  • [2024-10-14 11:39:20]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int N = 5e3 + 10;

int n, idx, l[N], r[N], a[N], s[N], sz[N], rx[N], rs[N];

struct F
{
	int i, j;
	
	bool operator> (const F& f2) const
	{
		return i * f2.j > j * f2.i;
	}
	
}ans[N];

int dp[N][N], tmp[N];
vector<int> son[N];
vector<int> rg[N];
map<array<int, 2>, int> mp;

int build(int l, int r)
{
	idx++, ::l[idx] = l, ::r[idx] = r, mp[{l, r}] = idx;
	sz[idx] = 1;
	int x = idx; rx[x] = r - l + 1, rs[x] = s[r] - s[l - 1];
	for (int i = l; i <= r; i++)
	{
		if (rg[i].empty()) continue;
		int j = rg[i].back(); rg[i].pop_back();
		int y = build(i, j);
		son[x].push_back(y);
		rx[x] -= (j - i + 1), rs[x] -= (s[j] - s[i - 1]);
		i = j;
	}
	return x;
}

template<class T>
void chkmax(T &x, T y)
{
	if (y > x) x = y;
}

void dfs(int x)
{
	memset(dp[x], -0x3f, sizeof dp[x]);
	dp[x][r[x]] = 0;
	sz[x] = r[x];
	for (int y : son[x])
	{
		dfs(y);
		for (int i = 0; i <= sz[x] + sz[y]; i++) tmp[i] = 0;
		for (int i = 0; i <= sz[x]; i++)
			for (int j = 0; j <= sz[y]; j++)
				chkmax(tmp[i + j], dp[x][i] + dp[y][j]);
		for (int i = 0; i <= sz[x] + sz[y]; i++) dp[x][i] = tmp[i];
		sz[x] += sz[y];
 	}
 	chkmax(dp[x][0], 0ll);
}

void initialize(vector<signed> A)
{
    n = (int)(A.size());
    for (int i = 1; i <= n; i++) a[i] = A[i - 1];
	for (int i = 1; i <= n; i++) s[i] = a[i] + s[i - 1];
    vector<int> s;
    for (int i = n; i >= 1; i--)
    {
    	while (!s.empty() && a[s.back()] > a[i])
    	{
    		int x = s.back(); s.pop_back();
    		if (x != i + 1) rg[i + 1].push_back(x - 1);
    	}
    	if (!s.empty() && s.back() != i + 1) rg[i + 1].push_back(s.back() - 1); 
    	if (!s.empty() && a[s.back()] >= a[i]) s.pop_back();
    	s.push_back(i);
    }
//	for (int i = 1; i <= n; i++)
//		for (int j : rg[i]) printf("[%d, %d]\n", i, j);
    
    build(2, n - 1);
    dfs(1);
    
    for (int i = 1; i <= n; i++)
    {
    	ans[i] = {0, 1};
    	for (int j = 0; j <= n; j++)
			chkmax(ans[i], F{dp[i][j] + a[l[i] - 1] + a[r[i] + 1], j + 2});    
		int d = __gcd(ans[i].i, ans[i].j);
		ans[i].i /= d, ans[i].j /= d;
	}
//    for (int i = 1; i <= n; i++)
//    	for (int j : son[i]) printf("[%d, %d] -> [%d, %d]\n", l[i], r[i], l[j], r[j]);
}

array<long long, 2> maximum_average(int i, int j)
{
	int id = mp[{i + 1, j - 1}];
	return {ans[id].i, ans[id].j};
}

//signed main()
//{
//	int n; cin >> n;
//	vector<int> A;
//	for (int i = 1, ai; i <= n; i++) cin >> ai, A.push_back(ai); 
//	initialize(A);
//	while (1)
//	{
//		int l, r; cin >> l >> r;
//		auto res = maximum_average(l, r);
//		cout << res[0] << ' ' << res[1] << endl;
//	}
//}

详细

/usr/bin/ld: /tmp/ccrAOMmd.o: in function `main':
implementer.cpp:(.text.startup+0x198): undefined reference to `maximum_average(int, int)'
collect2: error: ld returned 1 exit status