QOJ.ac

QOJ

実行時間制限: 4 s メモリ制限: 256 MB 満点: 100

#17141. 三个询问

統計

给定一个长度为 $n$ 的数组 $a$ 和 $q$ 次询问。我们还有一个无限长的二进制数组 $w$,初始时所有 $w_i = 1$。

存在以下三种类型的询问:

  • “1 x” —— 翻转 $w_x$ 的值(从 $1$ 变为 $0$,或从 $0$ 变为 $1$)。
  • “2 l r” —— 统计数组 $a$ 在区间 $[l, r]$ 内满足 $w_{a_i} = 1$ 且 $l \le i \le r$ 的不同数值的个数。
  • “3 x t” —— 将 $a_x$ 的值修改为 $t$。

对于每个第二类询问,输出对应的答案。

输入格式

第一行包含两个整数 $n$ 和 $q$($1 \le n, q \le 3 \cdot 10^5$)—— 数组的长度和询问的次数。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$($1 \le a_i \le 10^9$)—— 数组元素的初始值。

接下来的 $q$ 行,每行以一个整数 $type$($1 \le type \le 3$)开头,表示询问的类型:

  • 如果 $type = 1$,则该询问包含一个整数 $x$($1 \le x \le 10^9$)—— 翻转 $w_x$ 的值。
  • 如果 $type = 2$,则该询问包含两个整数 $l$ 和 $r$($1 \le l \le r \le n$)—— 统计数组 $a$ 在区间 $[l, r]$ 内满足 $w_{a_i} = 1$ 且 $l \le i \le r$ 的不同数值的个数。
  • 如果 $type = 3$,则该询问包含两个整数 $x$ 和 $t$($1 \le x \le n, 1 \le t \le 10^9$)—— 将 $a_x$ 的值替换为 $t$。

输出格式

对于每个第二类询问,在单独的一行中输出该区间内满足条件的不同数值的个数。

子任务

  1. (8 分):$n, q \le 10^3$;
  2. (6 分):仅包含第二类询问;$n = q$;$l_i = 1$;$r_i = i$;
  3. (13 分):仅包含第二类询问;
  4. (10 分):仅包含第一类和第二类询问;所有的 $a_i$ 两两不同;
  5. (14 分):仅包含第一类和第二类询问;所有的 $w_{a_i}$ 最多只能改变一次;
  6. (7 分):仅包含第一类和第二类询问;
  7. (14 分):仅包含第二类和第三类询问;
  8. (8 分):在任意时刻,恒有 $a_i \le 100$;
  9. (10 分):$n, q \le 5 \cdot 10^4$;
  10. (10 分):无附加限制。

样例

输入样例 1

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

输出样例 1

2
1
2

说明

在样例中,对于第一个第二类询问,区间对应的子数组为 $[4, 3, 4, 3]$(即 $a_2, a_3, a_4, a_5$),其中包含数字 $3$ 和 $4$。由于 $w_3$ 和 $w_4$ 都等于 $1$,因此答案为 $2$。

在接下来的第一类询问之后,$w_3$ 变为 $0$。因此对于下一个询问,答案为 $1$(只有 $4$ 满足条件,因为 $w_4 = 1$ 且 $w_3 = 0$)。

在接下来的第三类询问之后,整个数组变为 $[3, 4, 3, 5, 3, 2, 3, 1, 2, 1]$。

在最后一个询问中,区间对应的子数组为 $[4, 3, 5, 3]$,其中包含数字 $3, 4, 5$。由于 $w_3 = 0$,$w_4 = 1$,$w_5 = 1$,因此答案为 $2$(满足条件的数字为 $4$ 和 $5$)。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.