CF1905E.One-X

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In this sad world full of imperfections, ugly segment trees exist.

A segment tree is a tree where each node represents a segment and has its number. A segment tree for an array of nn elements can be built in a recursive manner. Let's say function build⁡(v,l,r)\operatorname{build}(v,l,r) builds the segment tree rooted in the node with number vv and it corresponds to the segment [l,r][l,r].

Now let's define build⁡(v,l,r)\operatorname{build}(v,l,r):

  • If l=rl=r, this node vv is a leaf so we stop adding more edges
  • Else, we add the edges (v,2v)(v, 2v) and (v,2v+1)(v, 2v+1). Let m=⌊l+r2⌋m=\lfloor \frac{l+r}{2} \rfloor. Then we call build⁡(2v,l,m)\operatorname{build}(2v,l,m) and build⁡(2v+1,m+1,r)\operatorname{build}(2v+1,m+1,r).

So, the whole tree is built by calling build⁡(1,1,n)\operatorname{build}(1,1,n).

Now Ibti will construct a segment tree for an array with nn elements. He wants to find the sum of lca⁡†(S)\operatorname{lca}^\dagger(S), where SS is a non-empty subset of leaves. Notice that there are exactly 2n−12^n - 1 possible subsets. Since this sum can be very large, output it modulo 998 244 353998\,244\,353.

†lca⁡(S)^\dagger\operatorname{lca}(S) is the number of the least common ancestor for the nodes that are in SS.

在这个充满缺憾的悲伤世界中,丑陋的线段树确实存在。

线段树是一种树形结构,其中每个节点代表一个区间并拥有一个编号。对于一个包含 nn 个元素的数组,其线段树可通过递归方式构建。我们定义函数 build⁡(v,l,r)\operatorname{build}(v,l,r) 表示以编号为 vv 的节点为根、对应区间为 [l,r][l,r] 的线段树的构建过程。

下面给出 build⁡(v,l,r)\operatorname{build}(v,l,r) 的定义:

  • 若 l=rl=r,则该节点 vv 是叶子节点,不再添加新的边;
  • 否则,添加两条边 (v,2v)(v, 2v) 和 (v,2v+1)(v, 2v+1);令 m=⌊l+r2⌋m=\lfloor \frac{l+r}{2} \rfloor,然后递归调用 build⁡(2v,l,m)\operatorname{build}(2v,l,m) 和 build⁡(2v+1,m+1,r)\operatorname{build}(2v+1,m+1,r)。

因此,整棵线段树通过调用 build⁡(1,1,n)\operatorname{build}(1,1,n) 构建而成。

现在 Ibti 将为一个含 nn 个元素的数组构造一棵线段树。他希望求出所有非空叶子节点子集 SS 对应的 lca⁡†(S)\operatorname{lca}^\dagger(S) 的总和。注意这样的子集共有 2n−12^n - 1 个。由于该总和可能非常大,请将结果对 998 244 353998\,244\,353 取模后输出。

†lca⁡(S)^\dagger\operatorname{lca}(S) 表示集合 SS 中所有节点的最近公共祖先(LCA)的编号。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1031 \le t \le 10^3) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤10182 \le n \le 10^{18}) — the length of the array for which the segment tree is built.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1031 \le t \le 10^3),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤10182 \le n \le 10^{18}),表示为其构建线段树的数组长度。

输出格式

For each test case, output a single integer — the required sum modulo 998 244 353998\,244\,353.

对于每个测试用例,输出一个整数——所求的和对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    5
    2
    3
    4
    5
    53278

    输出#1

    6
    17
    36
    69
    593324855

说明/提示

In the first test case:

Let's look at all subsets of leaves.

  • lca⁡(2)=2\operatorname{lca}({2})=2;
  • lca⁡(3)=3\operatorname{lca}({3})=3;
  • lca⁡(2,3)=1\operatorname{lca}({2,3})=1.

Thus, the answer is 2+3+1=62+3+1=6.

In the second test case:

Let's look at all subsets of leaves.

  • lca⁡(4)=4\operatorname{lca}({4})=4;
  • lca⁡(5)=5\operatorname{lca}({5})=5;
  • lca⁡(3)=3\operatorname{lca}({3})=3;
  • lca⁡(4,5)=2\operatorname{lca}({4,5})=2;
  • lca⁡(4,3)=1\operatorname{lca}({4,3})=1;
  • lca⁡(5,3)=1\operatorname{lca}({5,3})=1;
  • lca⁡(4,5,3)=1\operatorname{lca}({4,5,3})=1;

Thus, the answer is 4+5+3+2+1+1+1=174+5+3+2+1+1+1=17.

在第一个测试用例中:

我们考察所有叶子节点的子集。

  • lca⁡(2)=2\operatorname{lca}({2})=2;
  • lca⁡(3)=3\operatorname{lca}({3})=3;
  • lca⁡(2,3)=1\operatorname{lca}({2,3})=1。

因此,答案为 2+3+1=62+3+1=6。

在第二个测试用例中:

我们考察所有叶子节点的子集。

  • lca⁡(4)=4\operatorname{lca}({4})=4;
  • lca⁡(5)=5\operatorname{lca}({5})=5;
  • lca⁡(3)=3\operatorname{lca}({3})=3;
  • lca⁡(4,5)=2\operatorname{lca}({4,5})=2;
  • lca⁡(4,3)=1\operatorname{lca}({4,3})=1;
  • lca⁡(5,3)=1\operatorname{lca}({5,3})=1;
  • lca⁡(4,5,3)=1\operatorname{lca}({4,5,3})=1;

因此,答案为 4+5+3+2+1+1+1=174+5+3+2+1+1+1=17。

输入解题思路,AI测评打分。不知道怎么写?

首页