#P12547. [UOI 2025] Simple Subsequence

[UOI 2025] Simple Subsequence

题目描述

We call an array of integers d1,d2,,dmd_1, d_2, \ldots, d_m good if its length is equal to 00, or for any 1im1\le i\le m, both values j=1idj\sum\limits_{j=1}^{i} d_j and j=imdj\sum\limits_{j=i}^{m} d_j are non-negative. Here, j=lrdj\sum\limits_{j=l}^{r} d_j denotes dl+dl+1++drd_l+d_{l+1}+\ldots+d_{r}.

We define the beauty of the array as the length of its longest good subsequence1^1.

You are given an array aa of length nn, which consists of numbers 1-1 and 11.

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

  • replace the element apa_p with ap-a_p, where pp --- the parameter of the query;
  • find the beauty of the array consisting of elements [al,al+1,,ar][a_{l},a_{l+1},\ldots,a_r], where (l,r)(l, r) --- the parameters of the query.

输入格式

In the first line, two integers nn, qq are given (1n,q5105)(1\le n, q\le 5 \cdot 10^5) --- the length of the array aa and the number of queries, respectively.

In the second line, nn integers a1,a2,,ana_1, a_2, \ldots, a_n (ai{1,1})(a_i \in \{-1, 1\}) are given --- the elements of the array aa.

In the next qq lines, the description of the queries is given. The first of the numbers typeitype_i (1typei2)(1 \le type_i \le 2) denotes the type of the query. Queries of the first type are given in the format 1 p\texttt{1 p} (1pn)(1 \le p \le n), and queries of the second type are given in the format 2 l r\texttt{2 l r} (1lrn)(1 \le l \le r \le n).

输出格式

For each query of the second type, output one integer in a separate line --- the beauty of the corresponding array.

5 4
1 1 1 -1 1
2 1 5
1 3
2 1 4
2 2 5
5
2
3
4 4
1 1 1 -1
2 1 2
2 2 4
2 3 3
2 3 4
2
2
1
1

提示

1^1 An array cc is called a subsequence of an array bb if it is possible to remove a certain number of elements from the array bb (possibly zero) so that the array cc is formed. The empty array is a subsequence of any array.

Scoring

  • (22 points): ai=(1)i+1a_i = (-1)^{i+1} for 1in1 \le i \le n, and there are no type one queries;
  • (77 points): n16n \le 16, and there are no type one queries;
  • (2121 points): n,q100n, q \le 100;
  • (2020 points): n,q3000n, q \le 3000;
  • (2727 points): n,q2105n, q \leq 2 \cdot 10^5, and there are no type one queries;
  • (1414 points): n,q2105n, q \leq 2 \cdot 10^5;
  • (99 points): no additional restrictions.