首页 > 其他分享 >D. Effects of Anti Pimples

D. Effects of Anti Pimples

时间:2023-10-09 11:45:07浏览次数:31  
标签:among them Pimples 19 value black Effects Indices Anti

D. Effects of Anti Pimples

Chaneka has an array $[a_1,a_2,\ldots,a_n]$. Initially, all elements are white. Chaneka will choose one or more different indices and colour the elements at those chosen indices black. Then, she will choose all white elements whose indices are multiples of the index of at least one black element and colour those elements green. After that, her score is the maximum value of $a_i$ out of all black and green elements.

There are $2^n-1$ ways for Chaneka to choose the black indices. Find the sum of scores for all possible ways Chaneka can choose the black indices. Since the answer can be very big, print the answer modulo $998\,244\,353$.

Input

The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the size of array $a$.

The second line contains $n$ integers $a_1,a_2,a_3,\ldots,a_n$ ($0\leq a_i\leq10^5$).

Output

An integer representing the sum of scores for all possible ways Chaneka can choose the black indices, modulo $998\,244\,353$.

Examples

input

4
19 14 19 9

output

265

input

1
0

output

0

input

15
90000 9000 99000 900 90900 9900 99900 90 90090 9090 99090 990 90990 9990 99990

output

266012571

Note

In the first example, below are the $15$ possible ways to choose the black indices:

  • Index $1$ is black. Indices $2$, $3$, and $4$ are green. Maximum value among them is $19$.
  • Index $2$ is black. Index $4$ is green. Maximum value among them is $14$.
  • Index $3$ is black. Maximum value among them is $19$.
  • Index $4$ is black. Maximum value among them is $9$.
  • Indices $1$ and $2$ are black. Indices $3$ and $4$ are green. Maximum value among them is $19$.
  • Indices $1$ and $3$ are black. Indices $2$ and $4$ are green. Maximum value among them is $19$.
  • Indices $1$ and $4$ are black. Indices $2$ and $3$ are green. Maximum value among them is $19$.
  • Indices $2$ and $3$ are black. Index $4$ is green. Maximum value among them is $19$.
  • Indices $2$ and $4$ are black. Maximum value among them is $14$.
  • Indices $3$ and $4$ are black. Maximum value among them is $19$.
  • Indices $1$, $2$, and $3$ are black. Index $4$ is green. Maximum value among them is $19$.
  • Indices $1$, $2$, and $4$ are black. Index $3$ is green. Maximum value among them is $19$.
  • Indices $1$, $3$, and $4$ are black. Index $2$ is green. Maximum value among them is $19$.
  • Indices $2$, $3$, and $4$ are black. Maximum value among them is $19$.
  • Indices $1$, $2$, $3$, and $4$ are black. Maximum value among them is $19$.

The total sum is $19+14+19+9+19+19+19+19+14+19+19+19+19+19+19 = 265$.

 

解题思路

  如果要将下标 $i$ 染色,那么所有是 $i$ 的倍数的下标 $2i, \, 3i, \ldots$ 也会被染色,因此最大值的取值还要考虑到这些位置。定义数组 $b$,其中 $b_i$ 表示只对下标 $i$ 染色时能取到的最大值,即 $b_i = \max \left\{ a_i, \, a_{2i}, \, \ldots, \, a_{\left\lfloor \frac{n}{i} \right\rfloor i} \right\}$。如果某个方案中有 $k$ 个下标 $i_1, \, \ldots, \, i_k$ 染了黑色,那么其结果也就是最大值为 $\max\limits_{1 \leq j \leq k}\{ b_{i_j} \}$。

  我们不可能把 $2^n - 1$ 种方案全部枚举出来,意味着可以根据某个属性来对这些方案进行分类。可以发现所有方案的不同结果最多只有 $n$ 种,也就是不同 $b_i$ 的数量,因此我们可以根据方案的结果也就是最大值来进行分类,那么最多会有 $n$ 类,然后再通过组合计数来统计每一类贡献的答案是多少。

  考虑所有结果是 $w$ 的方案,意味着至少要染一个 $b_i = w$ 的下标,且不能染 $b_i > w$ 的下标(否则结果必然大于 $w$)。假设 $b_i = w$ 的下标有 $c_w$ 个,$b_i < w$ 的下标有 $s$ 个,那么结果是 $w$ 的方案的数量就是 $(2^{c_w}-1) \cdot 2^s$。其中 $2^{c_w}-1$ 是指在 $c_w$ 个 $b_i = w$ 的下标的所有染色方案中,除去均不染色的情况。$2^s$ 是指 $s$ 个 $b_i < w$ 的下标中的所有染色方案,这些下标是否染色都不会影响其结果是 $w$。所以这些方案对答案的贡献就是 $(2^{c_w}-1) \cdot 2^s \cdot w$。

  为此我们可以从小到大枚举 $b_i$,然后按照上面的方法对不同的 $b_i$ 分别统计答案即可。

  AC 代码如下,时间复杂度为 $O(n \log{n})$:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 typedef long long LL;
 5 
 6 const int N = 1e5 + 10, mod = 998244353;
 7 
 8 int a[N], b[N];
 9 
10 int qmi(int a, int k) {
11     int ret = 1;
12     while (k) {
13         if (k & 1) ret = 1ll * ret * a % mod;
14         a = 1ll * a * a % mod;
15         k >>= 1;
16     }
17     return ret;
18 }
19 
20 int main() {
21     int n;
22     scanf("%d", &n);
23     for (int i = 1; i <= n; i++) {
24         scanf("%d", a + i);
25     }
26     for (int i = 1; i <= n; i++) {
27         for (int j = i; j <= n; j += i) {
28             b[i] = max(b[i], a[j]);
29         }
30     }
31     sort(b + 1, b + n + 1);
32     int ret = 0;
33     for (int i = 1; i <= n; i++) {
34         int j = i + 1;
35         while (j <= n && b[j] == b[i]) {
36             j++;
37         }
38         ret = (ret + (qmi(2, j - i) - 1ll + mod) * qmi(2, i - 1) % mod * b[i]) % mod;
39         i = j - 1;
40     }
41     printf("%d", ret);
42     
43     return 0;
44 }

 

参考资料

  Codeforces Round #902 (Div. 1, Div. 2, based on COMPFEST 15 — Final Round) Editorial:https://codeforces.com/blog/entry/121200

标签:among,them,Pimples,19,value,black,Effects,Indices,Anti
From: https://www.cnblogs.com/onlyblues/p/17751311.html

相关文章

  • Qto_ReinforcingElementBaseQuantities
    Qto_ReinforcingElementBaseQuantities箍筋数量   NameTypeDescriptionCountQ_COUNT LengthQ_LENGTH WeightQ_WEIGHT    ############################......
  • 「Artlantis下载」Artlantis渲染器2020版 安装包下载方式
    Artlantis2020官方版是一款三维渲染软件,Artlantis2020官方版主要用于建筑绘图场景的三维渲染,对于建筑设计师来说,这款软件可以帮助极大提高渲染效率。软件可与市场上的所有3D建模软件兼容,是创建逼真的渲染和动画的最简单,最快的解决方案。自带渲染引擎,用户无需借助其他软件,专家和初......
  • 文章《Semantic Kernel -- LangChain 的替代品?》的错误和疑问 探讨
    微信公众号文章SemanticKernel——LangChain的替代品?[1],它使用的示例代码是Python,他却发了这么一个疑问:支持的语言对比(因为SemanticKernel是用C#开发的,所以它对C#比较支持)如上所示。不清楚SemanticKernel为什么要用C#来开发,C#相比Python和JavaScript来说使用......
  • 论文解读:HybridCR: weakly-supervised 3D point cloud semantic segmentation via hybr
    HybridCR:weakly-supervised3Dpointcloudsemanticsegmentationviahybridcontrastiveregularization基于混合对比学习正则化约束的增强方法,Li等人(2022a)使用极少标注(0.03%)在室内点云数据集上获得的分割精度为全监督方法的78.3%。是第一个利用点一致性并以端到端方式采用......
  • 【2.1】Pydantic使用方法
    【一】介绍Datavalidationandsettingsmanagementusingpythontypeannotations.使用Python的类型注解来进行数据校验和settings管理pydanticenforcestypehintsatruntime,andprovidesuserfriendlyerrorswhendataisinvalid.Pydantic可以在代码运行时提供类......
  • 【2.0】Starlette,Pydantic 与 FastAPI 框架是什么关系?
    【一】介绍Starlette是个什么项目;IDE开发时Python3.5+版本的"typehints"的好处:简短、直观和标准的Python类型声明;介绍Pydantic包,FastAPI项目的开发为什么要使用Pydantic【二】Starlette【1】介绍Starlette是一种轻量级的ASGI框架/工具包,是构建高性能......
  • After_Effects_2023_23.6.0.62图文安装教程及下载
    After_Effects_2023_23.6.0.62图文安装教程及下载AdobeAfterEffects2023_23.6.0.62(爱国版、一键式安装、永久使用)简称“AE”是Adobe公司推出的一款图形视频处理软件,适用于从事设计和视频特技的机构,包括电视台、动画制作公司、个人后期制作工作室以及多媒体工作室。最近一次更......
  • After_Effects_2023_23.5.0.52_ACR15.4图文安装教程及下载
     AdobeAfterEffects(爱国版、一键式安装、永久使用)简称“AE”是Adobe公司推出的一款图形视频处理软件,适用于从事设计和视频特技的机构,包括电视台、动画制作公司、个人后期制作工作室以及多媒体工作室。AdobeAfterEffects软件可以帮助您高效且精确地创建无数种引人注目的动态......
  • 更改Mantis的logo
    1准备好自己的logo,例如准备的logo为zhaoxiyu.gif、zxy.gif 2把上面的两个logo存放到C:/mantis-1.0.0a3/images 3打开C:/mantis-1.0.0a3/core中的html_api.php文件 4查找functionhtml_top_banner()在这个函数中更改echo'<ahref="http://www.Browan.com"title="Hello B......
  • 报错 image = image.resize((int(image.size[0] * (64 / image.size[1])), 64), Ima
    感谢大佬  https://blog.csdn.net/qq_37405087/article/details/131642749  修改ini配置文件 打开ini文件修改值  将其中的ANTIALIAS替换为LANCZOSimage=image.resize((int(image.size[0]*(64/image.size[1])),64),Image.ANTIALIAS).convert('L')  ......