311195: CF1948F. Rare Coins

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Rare Coinstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

There are $n$ bags numbered from $1$ to $n$, the $i$-th bag contains $a_i$ golden coins and $b_i$ silver coins.

The value of a gold coin is $1$. The value of a silver coin is either $0$ or $1$, determined for each silver coin independently ($0$ with probability $\frac{1}{2}$, $1$ with probability $\frac{1}{2}$).

You have to answer $q$ independent queries. Each query is the following:

  • $l$ $r$ — calculate the probability that the total value of coins in bags from $l$ to $r$ is strictly greater than the total value in all other bags.
Input

The first line contains two integers $n$ and $q$ ($1 \le n, q \le 3 \cdot 10^5$) — the number of bags and the number of queries, respectively.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^6$) — the number of gold coins in the $i$-th bag.

The third line contains $n$ integers $b_1, b_2, \dots, b_n$ ($0 \le b_i \le 10^6$) — the number of silver coins in the $i$-th bag.

Next $q$ lines contain queries. The $j$-th of the next $q$ lines contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$) — the description of the $j$-th query.

Additional constraints on the input:

  • the sum of the array $a$ doesn't exceed $10^6$;
  • the sum of the array $b$ doesn't exceed $10^6$.
Output

For each query, print one integer — the probability that the total value of coins in bags from $l$ to $r$ is strictly greater than the total value in all other bags, taken modulo $998244353$.

Formally, the probability can be expressed as an irreducible fraction $\frac{x}{y}$. You have to print the value of $x \cdot y^{-1} \bmod 998244353$, where $y^{-1}$ is an integer such that $y \cdot y^{-1} \bmod 998244353 = 1$.

ExamplesInput
2 2
1 0
0 2
2 2
1 1
Output
748683265 748683265 
Input
4 3
2 3 4 5
1 0 7 3
3 3
2 3
1 4
Output
997756929 273932289 1 
Note

In both queries from the first example, the answer is $\frac{1}{4}$.

Output

题目大意:
这个题目是关于计算一组袋子中金币和银币的概率问题。有 n 个袋子,编号从 1 到 n,第 i 个袋子包含 a_i 个金币和 b_i 个银币。金币的价值是 1,银币的价值是 0 或 1,每个银币的价值是独立确定的(0 的概率是 1/2,1 的概率也是 1/2)。需要回答 q 个独立查询,每个查询是:给定 l 和 r,计算袋子从 l 到 r 的金币和银币的总价值严格大于其他所有袋子总价值的概率。

输入输出数据格式:
输入:
- 第一行包含两个整数 n 和 q(1 ≤ n, q ≤ 3 * 10^5),分别是袋子的数量和查询的数量。
- 第二行包含 n 个整数 a_1, a_2, ..., a_n(0 ≤ a_i ≤ 10^6),表示第 i 个袋子中金币的数量。
- 第三行包含 n 个整数 b_1, b_2, ..., b_n(0 ≤ b_i ≤ 10^6),表示第 i 个袋子中银币的数量。
- 接下来的 q 行,每行包含两个整数 l_j 和 r_j(1 ≤ l_j ≤ r_j ≤ n),描述第 j 个查询。

输出:
- 对于每个查询,输出一个整数,表示袋子从 l 到 r 的金币和银币的总价值严格大于其他所有袋子总价值的概率,结果对 998244353 取模。
- 如果概率可以表示为不可约分数 x/y,则输出 x * y^(-1) mod 998244353,其中 y^(-1) 是一个整数,使得 y * y^(-1) mod 998244353 = 1。题目大意: 这个题目是关于计算一组袋子中金币和银币的概率问题。有 n 个袋子,编号从 1 到 n,第 i 个袋子包含 a_i 个金币和 b_i 个银币。金币的价值是 1,银币的价值是 0 或 1,每个银币的价值是独立确定的(0 的概率是 1/2,1 的概率也是 1/2)。需要回答 q 个独立查询,每个查询是:给定 l 和 r,计算袋子从 l 到 r 的金币和银币的总价值严格大于其他所有袋子总价值的概率。 输入输出数据格式: 输入: - 第一行包含两个整数 n 和 q(1 ≤ n, q ≤ 3 * 10^5),分别是袋子的数量和查询的数量。 - 第二行包含 n 个整数 a_1, a_2, ..., a_n(0 ≤ a_i ≤ 10^6),表示第 i 个袋子中金币的数量。 - 第三行包含 n 个整数 b_1, b_2, ..., b_n(0 ≤ b_i ≤ 10^6),表示第 i 个袋子中银币的数量。 - 接下来的 q 行,每行包含两个整数 l_j 和 r_j(1 ≤ l_j ≤ r_j ≤ n),描述第 j 个查询。 输出: - 对于每个查询,输出一个整数,表示袋子从 l 到 r 的金币和银币的总价值严格大于其他所有袋子总价值的概率,结果对 998244353 取模。 - 如果概率可以表示为不可约分数 x/y,则输出 x * y^(-1) mod 998244353,其中 y^(-1) 是一个整数,使得 y * y^(-1) mod 998244353 = 1。

加入题单

上一题 下一题 算法标签: