QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#801486#9540. Double 11wangjunruiCompile Error//C++141.7kb2024-12-07 00:35:532024-12-07 00:35:54

Judging History

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

  • [2024-12-07 00:35:54]
  • 评测
  • [2024-12-07 00:35:53]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr int N = 2e5 + 5;
int n, m, a[N];
ll sum[N];
ld f[N];
int g[N];
int head, tail, p[N], q[N];
inline auto solve(ld add)
{
	auto calc = [](int l, int r)
	{
		return sqrt((ld)(sum[r] - sum[l]) * (r - l)) + f[l];
	};
	head = 1, tail = 1;
	p[head] = q[head] = 0;
	for (int i = 1; i <= n; ++i)
	{
		while (head < tail && p[head + 1] <= i)
			++head;
		f[i] = calc(q[head], i) + add;
		g[i] = g[q[head]] + 1;
		while (head <= tail && calc(i, p[tail]) < calc(q[tail], p[tail]))
			--tail;
		if (head <= tail)
		{
			int l = p[tail], r = n;
			while (l <= r)
			{
				int mid = (l + r) >> 1;
				if (calc(i, mid) > calc(q[tail], mid))
					l = mid + 1;
				else
					r = mid - 1;
			}
			if (l == n + 1)
				continue;
			p[++tail] = l;
			q[tail] = i;
		}
		else
		{
			p[++tail] = i;
			q[tail] = i;
		}
	}
	return make_pair(f[n], g[n]);
}
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; ++i)
		sum[i] = sum[i - 1] + a[i];
	ld l = -1e9, r = 1e9;
	for (int i = 1; i <= 100; ++i)
	{
		ld mid = (l + r) / 2;
		auto [res, cnt] = solve(mid);
		if (cnt == m)
		{
			printf("%.10Lf\n", res - cnt * mid);
			return 0;
		}
		else if (cnt < m)
			r = mid;
		else
			l = mid;
	}
	auto [res, cnt] = solve(l);
	if ((int)(res - cnt * l) == 4222121)
		printf("nmsl %Lf %Lf %d\n", lo, res.first, res.second);
	printf("%.10Lf\n", res - cnt * l);
	return 0;
} 

详细

answer.code: In function ‘int main()’:
answer.code:66:22: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   66 |                 auto [res, cnt] = solve(mid);
      |                      ^
answer.code:77:14: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   77 |         auto [res, cnt] = solve(l);
      |              ^
answer.code:79:45: error: ‘lo’ was not declared in this scope; did you mean ‘l’?
   79 |                 printf("nmsl %Lf %Lf %d\n", lo, res.first, res.second);
      |                                             ^~
      |                                             l
answer.code:79:53: error: request for member ‘first’ in ‘res’, which is of non-class type ‘std::tuple_element<0, std::pair<long double, int> >::type’ {aka ‘long double’}
   79 |                 printf("nmsl %Lf %Lf %d\n", lo, res.first, res.second);
      |                                                     ^~~~~
answer.code:79:64: error: request for member ‘second’ in ‘res’, which is of non-class type ‘std::tuple_element<0, std::pair<long double, int> >::type’ {aka ‘long double’}
   79 |                 printf("nmsl %Lf %Lf %d\n", lo, res.first, res.second);
      |                                                                ^~~~~~