#4618. [UOI 2024] Queries for Subarray Beauty

[UOI 2024] Queries for Subarray Beauty

[UOI 2024] Queries for Subarray Beauty

题目描述

Let's call the **weight** of an array of integers $b$ of length $m$ the absolute value of the sum of its elements, i.e., $|b_1+b_2+...+b_m|$.

We define the beauty of a partition of array cc into several subarrays as the minimum weight among the weights of the subarrays. Formally, the beauty of a partition of array cc into kk subarrays $[c_1,\ldots,c_{p_1}],[c_{p_1+1},\ldots,c_{p_2}],\ldots,[c_{p_{k-1}+1},\ldots,c_{p_k}]$, where 1≤p1<p2<…<pk−1<pk=n1 \leq p_1 < p_2 < \ldots < p_{k-1} < p_k = n, is the value $\min(|c_1+\ldots+c_{p_1}|,|c_{p_1+1}+\ldots+c_{p_2}|,\ldots,|c_{p_{k-1}+1}+\ldots+c_{p_k}|)$. For example, the partition of the array [3,−6,4,5,−8][3,-6,4,5,-8] into subarrays [3,−6],[4],[5,−8][3,-6],[4],[5,-8] has a beauty of min⁡(∣3+(−6)∣,∣4∣,∣5+(−8)∣)=min⁡(3,4,3)=3\min(|3+(-6)|,|4|,|5+(-8)|)=\min(3,4,3)=3.

We define the beauty of an array cc as the maximum beauty among all possible partitions into subarrays.

An array of integers aa of length nn is given.

You need to perform qq queries. The queries can be of two types:

  • find the beauty of the subarray consisting of elements [al,al+1,…,ar][a_{l},a_{l+1},\ldots,a_r], where (ll, rr) are the query parameters;
  • replace the element axa_x with vv, where (xx, vv) are the query parameters.

输入格式

The first line contains two integers $n$, $q$ ($1\le n, q\le 10^6$) --- the length of array $a$ and the number of queries, respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−109≤ai≤109)-10^9\le a_i\le 10^9) --- the elements of array aa.

The next qq lines contain three integers each. The first of the numbers, typeitype_i (1≤typei≤21 \le type_i \le 2), denotes the type of the query. Queries of the first type are given in the format "1 l r\texttt{1 l r}" (1≤l≤r≤n1\le l\le r\le n), and queries of the second type are given in the format "2 x v\texttt{2 x v}" (1≤x≤n,1\le x\le n, −109≤v≤109-10^9\le v\le 10^9).

输出格式

For each query of the first type, output a single integer --- the **beauty** of the corresponding subarray.
6 4
1 -3 4 2 -5 6
1 1 6
1 2 3
1 2 5
1 1 1
5
3
3
1
5 6
1 -2 3 -4 5
1 1 4
1 2 3
2 3 -6
1 2 4
2 4 2
1 1 5
2
2
12
7

提示

In the first example, for the third query, the maximum beauty of the partition of the array $[-3,4,2,-5]$ is achieved when partitioned into subarrays $[-3],[4,2],[-5]$.

In the second example, for the first query, the maximum beauty of the partition of the array [1,−2,3,−4][1,-2,3,-4] is achieved when partitioned into subarrays [1,−2,3],[−4][1,-2,3],[-4].

Scoring

  • (44 points): typei=1type_i = 1 for 1≤i≤q1\le i\le q; ai>0a_i > 0 for 1≤i≤n1\le i\le n;
  • (1414 points): typei=1type_i = 1 for 1≤i≤q1\le i\le q; n,q≤1000n,q \le 1000;
  • (1010 points): typei=1type_i = 1 for 1≤i≤q1\le i\le q; n,q≤2⋅105n,q \le 2 \cdot 10^5, for each query there exists an optimal division into no more than 22 subarrays;
  • (1010 points): typei=1type_i = 1 for 1≤i≤q1\le i\le q; q≤n≤2⋅105q \le n \le 2 \cdot 10^5, li=1l_i = 1, ri=ir_i = i for 1≤i≤q1\le i\le q;
  • (1111 points): typei=1type_i = 1 for 1≤i≤q1\le i\le q; n,q≤2⋅105n,q \le 2 \cdot 10^5, −5≤∑j=1iaj≤5-5 \le \sum\limits_{j=1}^{i} a_j \le 5 for 1≤i≤n1\le i\le n;
  • (1818 points): typei=1type_i = 1 for 1≤i≤q1\le i\le q; n,q≤2⋅105n,q \le 2 \cdot 10^5;
  • (99 points): typei=1type_i = 1 for 1≤i≤q1\le i\le q;
  • (1616 points): n,q≤2⋅105n,q \le 2 \cdot 10^5;
  • (88 points): without additional constraints. 标签: P12554|2024|UOI(乌克兰)

来源

P12554|[UOI 2024] Queries for Subarray Beauty