#P16799. [蓝桥杯 2026 国 B] 实验数据

    ID: 19140 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>线段树树状数组2026蓝桥杯国赛

[蓝桥杯 2026 国 B] 实验数据

Problem Description

Xiao Lan is helping the teacher collect experimental data.

There are a total of nn experiments. The parameter of the ii-th experiment is ii, and the corresponding experimental data is aia_i. To analyze the relationship between the experimental parameters and the experimental data, Xiao Lan needs to query the average of the experimental data in a certain continuous interval multiple times. To measure the stability of the experimental results, he also needs to query the variance of the experimental data in that interval.

In addition, Xiao Lan may redo one experiment. If the kk-th experiment is redone, the original aka_k will be replaced by the new experimental data.

For a range query [l,r][l, r], let the interval length be len=r−l+1\textit{len} = r - l + 1, and the interval average be

aˉ=∑i=lrailen.\bar{a} = \frac{\sum_{i=l}^r a_i}{\textit{len}}.

In this problem, the interval variance is defined as

Var=∑i=lr(ai−aˉ)2.\mathrm{Var} = \sum_{i=l}^r (a_i - \bar{a})^2.

You need to support two types of operations:

  • Query the average and variance of the interval [l,r][l, r];
  • Modify the experimental data at some position kk to xx.

Since the answers may be rational numbers, to avoid precision errors, all query results should be output modulo 998244353998244353.

Specifically, suppose an answer is a rational number xx. Write xx as an irreducible fraction

x=pq,x = \frac{p}{q},

where pp and qq are integers, q>0q > 0, and gcd⁡(p,q)=1\gcd(p, q) = 1. This problem guarantees that qq is coprime with 998244353998244353.

Output an integer yy satisfying

$$\begin{aligned} 0 \le y < 998244353, y \equiv p \cdot q^{-1} \pmod{998244353}, \end{aligned}$$

where q−1q^{-1} denotes the multiplicative inverse of qq modulo 998244353998244353.

Input Format

The first line contains two positive integers n,mn, m, representing the number of experiments and the number of operations.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n, representing the initial experimental data.

The next mm lines each describe an operation in one of the following two formats:

  • 1 l r: query the average and variance of the experimental data in the interval [l,r][l, r];
  • 2 k x: modify aka_k to xx.

Output Format

For each 1 l r operation, output one line with two integers, representing the interval average and interval variance modulo 998244353998244353. Both results should be output according to the rational-number modulo rule described above.

4 5
1 3 2 4
1 1 3
1 2 4
2 3 5
1 1 3
1 2 4
2 2
3 2
3 8
4 2

Hint

Sample Explanation

For the first query on interval [1,3][1, 3], the data are 1,3,21, 3, 2. The average is 22, and the variance is

(1−2)2+(3−2)2+(2−2)2=2.(1 - 2)^2 + (3 - 2)^2 + (2 - 2)^2 = 2.

For the second query on interval [2,4][2, 4], the data are 3,2,43, 2, 4. The average is 33, and the variance is 22. Then a3a_3 is modified to 55, and the sequence becomes 1,3,5,41, 3, 5, 4.

For the third query on interval [1,3][1, 3], the average is 33, and the variance is 88.

For the fourth query on interval [2,4][2, 4], the average is 44, and the variance is 22.

Constraints and Conventions

For 50%50\% of the testdata, it is guaranteed that n,m≤3000n, m \le 3000.

For another 20%20\% of the testdata, there is no operation 2 k x.

For all testdata, it is guaranteed that:

  • 1≤n,m≤3×1051 \le n, m \le 3 \times 10^5;
  • 0≤ai,x≤9982443530 \le a_i, x \le 998244353;
  • For all query operations, 1≤l≤r≤n1 \le l \le r \le n;
  • For all modification operations, 1≤k≤n1 \le k \le n.

Translated by ChatGPT 5