首页 > 其他分享 >POI2011Lightning Conductor

POI2011Lightning Conductor

时间:2024-04-20 16:56:57浏览次数:28  
标签:Conductor int ll mid pos POI2011Lightning calc dp

POI #Year2011 #dp #决策单调性

令 \(dp_i=\max\limits_{j=1}^{i-1}{a_j+\sqrt{i-j})}\)

\(w(j,i)=\sqrt{i-j}\) 满足四边形不等式

所以这个 \(dp\) 具有决策单调性,分治维护

// Author: xiaruize
const int N = 5e5 + 10;

int n;
int a[N];
double dp[N];

double w(int x, int y)
{
	return (double)a[x] + sqrt(y - x);
}

void calc(int l, int r, int ll, int rr)
{
	// debug(l, r, ll, rr);
	if (l > r)
		return;
	int mid = l + r >> 1;
	double mx = 0;
	int pos = 0;
	rep(i, ll, min(mid, rr))
	{
		if (w(i, mid) > mx)
		{
			mx = w(i, mid);
			pos = i;
		}
	}
	dp[mid] = max(mx, dp[mid]);
	calc(l, mid - 1, ll, pos);
	calc(mid + 1, r, pos, rr);
}

void solve()
{
	cin >> n;
	rep(i, 1, n) cin >> a[i];
	calc(1, n, 1, n);
	debug("flag");
	reverse(a + 1, a + n + 1);
	reverse(dp + 1, dp + n + 1);
	calc(1, n, 1, n);
	per(i, n, 1)
	{
		// debug(dp[i]);
		cout << (int)(ceil(dp[i])) - a[i] << endl;
	}
}

#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif

signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int testcase = 1;
	// cin >> testcase;
	while (testcase--)
		solve();
#ifndef ONLINE_JUDGE
	cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
	cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
	return 0;
}

标签:Conductor,int,ll,mid,pos,POI2011Lightning,calc,dp
From: https://www.cnblogs.com/xiaruize/p/18147872

相关文章

  • netflix conductor 停止维护
    就在23年的12月底,netflixconductor团队停止了对于conductor社区版的维护,同时github项目只读了目前社区有一个fork的conductor-oss(orkes团队维护,团队成员来自netflix),orkes属于一个企业级的conductor平台参考资料https://github.com/Netflix/conductorhttps://github.com......
  • 【题解】P3515 [POI2011]Lightning Conductor(二分栈/分治优化DP)
    [POI2011]LightningConductor题面翻译给定一个长度为\(n\)的序列\(\{a_n\}\),对于每个\(i\in[1,n]\),求出一个最小的非负整数\(p\),使得\(\forallj\in[1,n]\),都......
  • 【POI2011】Lightning Conductor_【JSOI2016】灯塔(决策单调性优化dp)
    首先进行变形:\[\begin{aligned}a_j&\leqa_i+p-\sqrt{|i-j|}\\p&\geq\max_{j=1}^n\left(a_j+\sqrt{|i-j|}\right)-a_i\end{aligned}\]把\(|i-j|\)拆为\(\max(i-j......
  • [POI2011]Lightning Conductor
    做题时间:2022.10.14\(【题目描述】\)给定一个长度为\(n(n\leq5\times10^5)\)的非负整数序列\(a(a_i\leq10^9)\),对于\(\foralli\in[1,n]\),求出最小的非负整数\(p......
  • Semiconductor
    Someofthepropertiesofsemiconductormaterialswereobservedthroughoutthemid19thandfirstdecadesofthe20thcentury.Developmentsinquantumphysics......