#P15094. [UOI 2025 II Stage] Three Queries

[UOI 2025 II Stage] Three Queries

题目描述

Given an array aa of length nn and qq queries. We also have a binary array ww of infinite length, initially all wi=1w_i=1.

There are three types of queries:

  • 1 x1 \ x --- toggle the value of wxw_x (from 11 to 00, and vice versa).
  • 2 l r2 \ l \ r --- count the number of unique numbers in the array aa in the range [l,r][l, r] for which wai=1w_{a_i}=1 and lirl \le i \le r.
  • 3 x t3 \ x \ t --- assign the value tt to axa_x.

Provide an answer for each query of the second type.

输入格式

The first line contains two integers nn and qq (1n,q3105)(1 \le n, q \le 3\cdot10^5)~--- the length of the array and the number of queries.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai109)(1 \le a_i \le 10^9)~--- the values of the elements of the array.

Each of the following qq lines starts with an integer typetype (1type3)(1 \le type \le 3) --- the type number of each query:

  • If type=1type = 1, the query contains one integer xx (1x109)(1 \le x \le 10^9) --- toggle the value of wxw_x.
  • If type=2type = 2, the query contains two integers ll and rr (1lrn)(1 \le l \le r \le n) --- count the number of unique numbers in the array aa in the range [l,r][l, r] for which wai=1w_{a_i}=1 and lirl \le i \le r.
  • If type=3type = 3, the query contains two integers xx and tt (1xn,1t109)(1 \le x \le n, 1 \le t \le 10^9) --- replace the value of axa_x with tt.

输出格式

For each query of the second type, output the number of unique numbers in the range on a separate line.

10 5
3 4 3 4 3 2 3 1 2 1
2 2 5
1 3
2 2 5
3 4 5
2 2 5
2
1
2

提示

In the example for the first query of the second type, the segment looks like [4,3,4,3][4, 3, 4, 3], meaning there are numbers 33, 44, and w3w_3, w4w_4 are equal to 11, so the answer is 22. After the next query of type 11, w3w_3 becomes 00, so for the next query, the answer is 11. After the next query, the array will look like [3,4,3,5,3,2,3,1,2,1][3, 4, 3, 5, 3, 2, 3, 1, 2, 1]. In the last query, the segment will look like [4,3,5,3][4, 3, 5, 3], meaning there are numbers 3,4,53, 4, 5, respectively the answer is 22, because w3=0w_3 = 0.

Scoring

  • (88 points): n,q103n, q \le 10^3;
  • (66 points): only queries of type 22; n=q;li=1n=q; l_i=1; ri=ir_i=i;
  • (1313 points): only queries of type 22;
  • (1010 points): only queries of type 11 and 22; all aia_i are pairwise distinct;
  • (1414 points): only queries of type 11 and 22; all waiw_{a_i} can change only once;
  • (77 points): only queries of type 11 and 22;
  • (1414 points): only queries of type 22 and 33;
  • (88 points): at any moment, ai100a_i \le 100;
  • (1010 points): n,q5104n, q \le 5\cdot10^4;
  • (1010 points): without additional constraints.