CF2182F2.Christmas Reindeer (hard version)
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the hard version of the problem. The only difference between the versions is the upper bound on n and m. In this version, n≤3⋅105 and m≤3⋅105.
You have a herd of n Christmas reindeer. The strength of the i-th reindeer is 2ci.
The carrying capacity of a group of k Christmas reindeer is calculated as follows:
- the strengths of the reindeer are sorted in non-increasing order. Let's denote the sorted list of strengths as c1′,c2′,…,ck′, where ci′≥ci+1′;
- then, the carrying capacity of this group of reindeer is equal to c1′+⌊2c2′⌋+⌊4c3′⌋+⋯+⌊2k−1ck′⌋.
Note that some reindeer may contribute zero to the carrying capacity of the group.
You have to process queries of three types:
- add a reindeer with strength equal to 2x to the herd;
- remove a reindeer with strength equal to 2x from the herd of reindeer;
- calculate the number of ways to choose some of the reindeer from the herd (possibly all of them) so that the carrying capacity of the chosen group is at least x.
If there are multiple reindeer with the same strength in the herd, they are considered different. For example, if you have two reindeer with strength 1 each, and you need to calculate the number of ways to choose a group with carrying capacity of at least 1, there are 3 ways to choose it: choose the first reindeer, the second reindeer, or both of them.
这是该问题的困难版本。两个版本的唯一区别在于 n 和 m 的上界。在本版本中,n≤3⋅105 且 m≤3⋅105。
你有一群 n 只圣诞驯鹿。第 i 只驯鹿的力量为 2ci。
一组 k 只圣诞驯鹿的承载能力按如下方式计算:
- 将这群驯鹿的力量按非递增顺序排序。记排序后的力量序列为 c1′,c2′,…,ck′,其中 ci′≥ci+1′;
- 则该组驯鹿的承载能力等于
c1′+⌊2c2′⌋+⌊4c3′⌋+⋯+⌊2k−1ck′⌋.
注意:某些驯鹿对群体承载能力的贡献可能为零。
你需要处理三种类型的查询:
- 向驯鹿群中添加一只力量为 2x 的驯鹿;
- 从驯鹿群中移除一只力量为 2x 的驯鹿;
- 计算从当前驯鹿群中选出若干只驯鹿(可以全选,也可以不选)的方式数,使得所选群体的承载能力至少为 x。
若驯鹿群中存在多只力量相同的驯鹿,则它们被视为互不相同。例如,若你有两只力量均为 1 的驯鹿,而你需要计算承载能力至少为 1 的选择方案数,则共有 3 种方案:仅选第一只、仅选第二只,或同时选两只。
输入格式
The first line contains two integers n and m (1≤n,m≤3⋅105) — the initial number of reindeer in the herd and the number of queries, respectively.
The second line contains n integers c1,c2,…,cn (0≤ci≤60) denoting the strengths of the reindeer in the herd: the strength of the i-th reindeer is 2ci.
The next m lines describe the queries in one of the following formats:
- 1 x (0≤x≤60) — add a reindeer with strength equal to 2x to the herd;
- 2 x (0≤x≤60) — remove a reindeer with strength equal to 2x from the herd;
- 3 x (1≤x≤1018) — calculate the number of ways to choose a group of reindeer from the herd so that the carrying capacity of the chosen group is at least x.
Additional constraint on the input: whenever a query of type 2 is given, the herd currently contains at least one reindeer with strength equal to 2x.
第一行包含两个整数 n 和 m(1≤n,m≤3⋅105),分别表示鹿群中初始的驯鹿数量以及查询次数。
第二行包含 n 个整数 c1,c2,…,cn(0≤ci≤60),表示鹿群中各驯鹿的力量值:第 i 只驯鹿的力量为 2ci。
接下来的 m 行描述了 m 个查询,每个查询为以下格式之一:
- 1 x(0≤x≤60)——向鹿群中添加一只力量为 2x 的驯鹿;
- 2 x(0≤x≤60)——从鹿群中移除一只力量为 2x 的驯鹿;
- 3 x(1≤x≤1018)——计算从当前鹿群中选出一组驯鹿的方式数,使得该组驯鹿的总承载能力至少为 x。
输入附加约束:每当出现类型为 2 的查询时,鹿群中当前至少存在一只力量为 2x 的驯鹿。
输出格式
For each query of the third type, print a single integer — the number of ways to choose a group of reindeer from the herd (possibly the whole herd) so that the carrying capacity of the chosen group is at least x. Since it can be huge, print it modulo 998244353.
对于每个第三种类型的查询,输出一个整数——即从驯鹿群中(可能选择整个驯鹿群)选出一组驯鹿,使得该组驯鹿的承载能力至少为 x 的方案数。由于结果可能非常大,请对 998244353 取模后输出。
输入输出样例
输入#1
3 7 2 1 1 3 5 3 6 1 2 3 6 3 5 2 1 3 5
输出#1
3 0 4 10 4
输入#2
5 5 6 9 2 3 5 3 518 1 4 2 9 1 10 3 1016
输出#2
12 32
输入#3
5 20 56 58 31 56 57 3 584133699915613698 1 26 3 718934517698133644 1 43 3 853795525565803934 3 371128907885602007 1 54 1 25 3 12283451778216771 2 25 3 269837405423769340 1 0 3 81332884431075468 1 23 3 4256984962444022 3 668408003982766102 3 923410222653374550 3 340313743235311415 3 550166282440775769 3 445344499963496530
输出#3
0 0 0 24 496 128 416 992 0 0 320 0 0
说明/提示
Let's consider the first example. Initially, there are three reindeer with strength equal to 4, 2 and 2, respectively.
- during the first query, you have to calculate the number of ways to choose a group with carrying capacity of at least 5. There are three possible groups: 1,2 (the group containing the 1-st and the 2-nd reindeer), 1,2,3, and 1,3;
- during the second query, you have to calculate the number of ways to choose a group with carrying capacity of at least 6. Even the whole herd has carrying capacity equal to 4+⌊22⌋+⌊42⌋=5, so there are no suitable ways to choose a group;
- during the third query, a reindeer with strength 4 is added. Let's denote it as the 4-th reindeer;
- during the fourth query, the possible groups are 1,4, 1,2,4, 1,3,4 and 1,2,3,4;
- during the fifth query, there are 10 possible groups;
- during the sixth query, a reindeer with strength 2 is removed. Let's say that it was the 2-nd reindeer, so only reindeer 1,3,4 remain;
- during the seventh query, you have to calculate the number of ways to choose a group with carrying capacity of at least 5. There are four possible groups: 1,3, 1,4, 1,3,4, 3,4.
我们来考虑第一个例子。初始时有三只驯鹿,其力量值分别为 4、2 和 2。
- 在第一次查询中,你需要计算选出一个承载能力至少为 5 的群体的方法数。共有三种可能的群体:1,2(包含第 1 只和第 2 只驯鹿的群体)、1,2,3 和 1,3;
- 在第二次查询中,你需要计算选出一个承载能力至少为 6 的群体的方法数。即使整个鹿群的承载能力也仅为 4+⌊22⌋+⌊42⌋=5,因此不存在满足条件的群体;
- 在第三次查询中,加入一只力量值为 4 的驯鹿;我们将其记作第 4 只驯鹿;
- 在第四次查询中,可能的群体有 1,4、1,2,4、1,3,4 和 1,2,3,4;
- 在第五次查询中,共有 10 种可能的群体;
- 在第六次查询中,移除一只力量值为 2 的驯鹿;假设被移除的是第 2 只驯鹿,则剩余驯鹿为第 1、3、4 只;
- 在第七次查询中,你需要计算选出一个承载能力至少为 5 的群体的方法数。共有四种可能的群体:1,3、1,4、1,3,4、3,4。
输入解题思路,AI测评打分。不知道怎么写?