D. Effects of Anti Pimples

D. Effects of Anti Pimples

思路:
1.设f[i]=max(a[i],a[i*2],...),选i时的最大值
2.f进行从大到小排序
3.我们如果选了f[i],要保证选法的最大值是f[i]的方法因该为2^(n-i),因为选后面的一定保证最大值小于f[i]

规律:
1.我们发现1与后面的组合的最大值等于数列的最大值,次数是2^(n-1),这是巧合吗?
2.往下递推,我们可知2与后面的组合为2的倍数的最大值,次数为2^(n-2),...
3.因此我们可以先算出每个位置的最大值,然后乘以相应的次数

点击查看代码
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e5 + 10,mod= 998244353;
int a[N],b[N];
LL _pow(LL a, int b) {
	LL ans = 1;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		a = 1LL*a * a % mod;
		b >>= 1;
	}
	return ans;
}
void solve() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j+=i) {
			b[i] = max(b[i], a[j]);
		}
	}
	sort(b + 1, b + 1 + n);
	LL ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = (ans +b[i]*_pow(2,i-1)) % mod;
	}
	cout << ans;
	cout << '\n';
}
int main() {
	int t=1;
	//cin >> t;
	while (t--) {
		solve();
	}
}
posted @   不o凡  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示